# how to make return value in for loop ?

조회 수: 159(최근 30일)
ElizabethR 2016년 3월 11일
댓글: ElizabethR 2016년 3월 12일
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 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:
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 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 :)

댓글을 달려면 로그인하십시오.

### 범주

Find more on Loops and Conditional Statements 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!