Related to function call

1 vue (au cours des 30 derniers jours)
SHRUTHI k
SHRUTHI k le 14 Sep 2015
Commenté : SHRUTHI k le 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.

Réponse acceptée

Guillaume
Guillaume le 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 commentaires
Walter Roberson
Walter Roberson le 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 le 16 Sep 2015
OK...thank you..

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Performance and Memory dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by