Error: Too many output arguments

285 views (last 30 days)
Alex Vasin
Alex Vasin on 14 May 2017
Commented: Star Strider on 4 Nov 2021
Hi. In my main M script I have:
x = 0:50;
y = 0:50;
[X,Y] = meshgrid(x,y);
P = P_fn(X,Y);
in my function I have:
functionP_fn(x,y)
P = involving both terms x and y>
end
when I run it I get the error:
>> P = P_fn(X,Y);
Error using P_fn
Too many output arguments.
Can functions only output one calculation and output? My equation works just fine if I use it in the main M script.
Thanks for reading

Accepted Answer

Star Strider
Star Strider on 14 May 2017
The error is because you did not define the function with outputs.
Try this:
functionP = P_fn(x,y)
P = involving both terms x and y>
end
4 Comments
Star Strider
Star Strider on 15 Sep 2021
This should be a new Question.
b = myRand
b = 3×4
1.4722 0.2712 7.6027 8.2860 4.9290 5.6392 1.6085 8.6403 8.9170 5.5582 5.6037 7.0630
functiona = myRand
a = 10*rand(3,4);
end
That said, it works for me, so problem solved!
.

Sign in to comment.

More Answers (1)

Bartomeu Serra Gonzalez
Bartomeu Serra Gonzalez on 4 Nov 2021
Mi función es la siguiente:
y a la hora de ejecutar, en un scrip:
me aparece el error:
¿Porqué?
1 Comment
Star Strider
Star Strider on 4 Nov 2021
The ‘f’ function does not return anything, although the anonymous function within it does.

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by