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
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!
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!