MATLAB Answers

Related to function call

2 views (last 30 days)
SHRUTHI k on 14 Sep 2015
Commented: SHRUTHI k on 16 Sep 2015
Hello..I seek help in writing MATLAB code. I have written a code for some operation and I am getting the result. But I want to call this functio code in my main code. I know how to do function call but i don't know which syntax to use at the end of function code so that I can pass the final value to my main code. For example, I have a code for convolution "my_conv.m" without using builin conv(x,h). In my main code I used the syntax "my_conv(..,..);" for function call. Which syntax I need to use at the end of "my_conv" for passing the result to main code? Similar to this I am using many other functions for different operations. Thank you in advance.


Sign in to comment.

Accepted Answer

Guillaume on 14 Sep 2015
Have you looked at the help of function? It's all explained in there.
You declare which variable you want to return in the first line of your code:
function returnvalue = myfunc(someinput, someotherinput)
%output of function is returnvalue
and you call it:
value = myfunc(a, b)
See the help linked above to see how to return more than one output from a function.


Show 3 older comments
SHRUTHI k on 16 Sep 2015
Hi.. Do you say every function syntax has end syntax as its pair? Like "for-end" pair, "if-end" pair, "function-end" is also a valid pair? every "function" we declare has to have an "end" command?
Walter Roberson
Walter Roberson on 16 Sep 2015
In .m files that start with "function", the rule is that you have to do it the same way every time: you can have functions that have matching "end", or you can have functions that do not have matching "end", but you cannot have both types in the same file. Having a matching "end" means something slightly different: it can be optimized more, but you cannot create new variables dynamically in the function by using eval() or related routines or by using load() without an output parameter.
SHRUTHI k on 16 Sep 2015
OK...thank you..

Sign in to comment.

More Answers (0)

Sign in to answer this question.

Translated by