Related to function call

1 view (last 30 days)
SHRUTHI k
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.

Accepted Answer

Guillaume
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
%...
end
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.
  6 Comments
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
SHRUTHI k on 16 Sep 2015
OK...thank you..

Sign in to comment.

More Answers (0)

Categories

Find more on Performance and Memory in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!