Error: Too many output arguments
265 ビュー (過去 30 日間)
古いコメントを表示
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:
function P_fn(x,y)
P = <some equation 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
0 件のコメント
採用された回答
Star Strider
2017 年 5 月 14 日
The error is because you did not define the function with outputs.
Try this:
function P = P_fn(x,y)
P = <some equation involving both terms x and y>
end
4 件のコメント
Hadjer BEN BRAHIM
2021 年 9 月 14 日
Please help me with my problem :
function a = myRand
a = 10*rand(3,4);
end
--------------
When I ran it
myRand ( it shows up)
Then I want to assign the result to a variable b :
b = myRand
And there is an error :
Error using myRand
Too many output arguments.
Star Strider
2021 年 9 月 15 日
This should be a new Question.
b = myRand
function a = myRand
a = 10*rand(3,4);
end
That said, it works for me, so problem solved!
.
その他の回答 (1 件)
Bartomeu Serra Gonzalez
2021 年 11 月 4 日
Mi función es la siguiente:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/789720/image.png)
y a la hora de ejecutar, en un scrip:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/789725/image.png)
me aparece el error:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/789730/image.png)
¿Porqué?
1 件のコメント
Star Strider
2021 年 11 月 4 日
The ‘f’ function does not return anything, although the anonymous function within it does.
参考
カテゴリ
Help Center および File Exchange で Author Block Masks についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!