how to make return value in for loop ?

58 ビュー (過去 30 日間)
ElizabethR
ElizabethR 2016 年 3 月 11 日
コメント済み: ElizabethR 2016 年 3 月 12 日
i have a code :
function rad = Radial(n,m);
radial=0; %zeros(size(r));
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)))
radial=radial+c*(radial^(n-2*s));
end
return radial;
but, i can return the value of radial, and then compute the radial value to loop again. How to fix ? thanks

採用された回答

Stephen23
Stephen23 2016 年 3 月 11 日
編集済み: Stephen23 2016 年 3 月 11 日
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:
function rad = Radial(n,m);
rad = ... whatever rad is;
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.
  1 件のコメント
ElizabethR
ElizabethR 2016 年 3 月 12 日
hello Stephen.. i am the begginer in matlab. Thanks you so much for your explanation. it's very helping me. God Bless You :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by