Reputation: 1013
I've created this small program just for simplicity of the question, I am having some trouble using my function inside a while loop
this is the script;
x = 1;
y = 1;
while x<10
y = func(x,y);
x = x + 1;
this is the function, func;
function [] = func(x,y)
y- exp(-x)
end
I get the error of
Error using func
Too many output arguments.
what am I doing wrong
Upvotes: 0
Views: 590
Reputation: 3417
When you declare the function:
function [] = func(x,y)
You have specified that there will be no return values, yet when you call it you require a return value:
y = func(x,y);
To fix this issue you must alter your function declaration, e.g.:
function y_out = func(x,y)
Also, within your function declaration you have y- exp(-x)
, which will not change the value of y
; did you intend to have y=exp(-x)
?
Upvotes: 2