# how to make return value in for loop ?

156 views (last 30 days)
ElizabethR on 11 Mar 2016
Commented: ElizabethR on 12 Mar 2016
i have a code :
for s=0:(n-abs(m))/2
c=(-1)^s*((factorial(n-s))/(factorial(s)*factorial(((n+abs(m))/2)-s)
*factorial(((n-abs(m))/2)-s)))
end
but, i can return the value of radial, and then compute the radial value to loop again. How to fix ? thanks

Stephen23 on 11 Mar 2016
Edited: Stephen23 on 11 Mar 2016
MATLAB does not need a return statement to return a value. To return a value you simply need to list it as an output argument of the function:
function [output1,output2,...] = fun_name(input1,input2,...)
You have specified an output argument rad, but then have totally ignored this inside your code an never allocated any value to it. You should try something like this:
end
Of course this is explained quite clearly in the introductory tutorials:
and also the function documentation:
Read the documentation. It tells you how MATLAB works.
If you want to store all of the values of rad in a loop then you can use indexing.
ElizabethR on 12 Mar 2016
hello Stephen.. i am the begginer in matlab. Thanks you so much for your explanation. it's very helping me. God Bless You :)