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.

回答(1 个)

Rajanya
Rajanya about 20 hours 前
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!

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by