Too many output error message when using function in a for loop

4 visualizaciones (últimos 30 días)
Brian Hom
Brian Hom el 5 de Feb. de 2018
Respondida: Rajanya hace alrededor de 4 horas
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.

Respuestas (1)

Rajanya
Rajanya hace alrededor de 3 horas
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!

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by