You are here:

CAD/Matlab output not showing

Advertisement


Question
Thanks.
Calling from cammand line, it is working fine.
Is it possible that I compile and run from the editor window itself? Should it work? Pl suggest.
-------------------------

Followup To

Question -
I have written a small programm as
function z = my_fun(x)
z = x(1)^2 - 2*x(1)*x(2) + 6*x(1) + x(2)^2 - 6*x(2);
my_fun([2 3])


but my MATLAB is not showing the output when it is run . what is wrong with it.

Answer -
Hi vinayakranjan,

your code runs fine in my machine. And i don't see a reason why not. Maybe you are doing something else wrong. Maybe you are calling my_fun in the wrong way. If you want to create the my_fun function, you should open a new document in the editor, type
function z = my_fun(x)
z = x(1)^2 - 2*x(1)*x(2) + 6*x(1) + x(2)^2 - 6*x(2);
and save the document as my_fun.m which is the standard name Matlab autofills when is sees you create a new function. Now, if you call the function from the command window by typing
my_fun([2 3])
it will return the correct answer. Don't include a call to your function in the function body. On the other hand, if you're trying to create a reccurent function, i don't think this would work as it will enter an infinite loop.

Best G.

Answer
Yes, it is possible. You can call a function either from the command window, from a script or another function. What you are looking for is a script. I suggest you read the matlab help file on scripts and functions in order to clarify how scripts and functions work.

Best
G.

CAD

All Answers


Answers by Expert:


Ask Experts

Volunteer


George Moustris

Expertise

I have extensive experience in MATLAB which is a CAD for engineers.I can answer many questions on the programming script as well as the use of many toolboxes Matlab uses.However DO NOT ask me about the underlying theory of your projects.I will only answer questions regarding the USE of Matlab.

Experience

I have written many scripts in Matlab utilizing many toolboxes and libraries such as Fuzzy Logic toolbox,Neural Nets,Image processing,Wavelets,Signal processing etc.

Organizations
Aristotle University of Thessaloniki

©2012 About.com, a part of The New York Times Company. All rights reserved.