multiple outputs from a function

Dear All,
I am facing a problem with delivering multiple outputs from a function. Take an example, function [a b c]= g()% no input a=1 b=2 c=3 end
However, this function will only deliver the value for a as the 'ans' and ignore value of b and c. I think I have made it clear that this function should deliver value for a, b and c. and they can be used for corresponding calculations in another function.
Could somebody help me with it?
Thank you very much in advance.

2 件のコメント

Matt J
Matt J 2013 年 1 月 11 日
Show what syntax you are using to call the function when it only gives you the first output argument.
James Tursa
James Tursa 2013 年 1 月 11 日
And what syntax are you using for the function g itself?

サインインしてコメントする。

 採用された回答

Matt J
Matt J 2013 年 1 月 11 日
編集済み: Matt J 2013 年 1 月 11 日

2 投票

If you are simply calling g() at the command line with no output arguments
>>g()
then MATLAB assumes that you only want 1 output argument and will assign that to ans.
If you want 2 or more output arguments, you must make that explicit, e.g.,
>>[a,b]=g()
or
>>[a,b,c]=g()

1 件のコメント

zhe li
zhe li 2013 年 1 月 14 日
Hi Matt,
Thanks very much for your help.
Zhe Li

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

2013 年 1 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by