Too many output error message when using function in a for loop
조회 수: 4 (최근 30일)
이전 댓글 표시
I am getting the "too many output arguments" error message when calling on a function that's within a for loop. heres my code.
function RFtable(lowerm2bound, upperm2bound, m2step, gamma, m_1);
n=(upperm2bound-lowerm2bound)/m2step;
m2values=linspace(lowerm2bound,upperm2bound,n)
for i=1:n+1
poverpstar(i)= RFp2overp1(gamma,m_1,m2values(i))
end
end
I stepped though the script and the error is occurring within the for loop. here's the code for the RFp2overp1 function.
function RFp2overp1(gamma,m_1,m_2)
(1+gamma*m_1^2)/(1+gamma*m_2^2)
end
Any advice would be great I think its something pretty simple.
댓글 수: 0
답변 (1개)
Rajanya
대략 9시간 전
The error occurs because the function ‘RFp2overp1’ does not return a value, but the following line in your code expects it to do so:
poverpstar(i)= RFp2overp1(gamma, m_1,m2values(i))
You can modify ‘RFp2overp1’ to include an output argument, which should fix this error.
function res = RFp2overp1(gamma, m_1,m_2)
res = (1+gamma*m_1^2)/(1+gamma*m_2^2)
end
Thanks!
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!