CAD/Matlab output not showing
Expert: George Moustris - 10/13/2006
QuestionThanks.
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.
AnswerYes, 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.