Get only one output from a function with several ones?

Suppose I define a function:
function [A,B] = myfun(x,y,z)
...
...
I know that if I type
[C,D] = myfun(1,1,1)
then I'll get both C (corresponding to A) and D (corresponding to B) for the specific values or if I type
C = myfun(1,1,1)
I'll get C (corresponding to A). Is there a way to get only D for these specific values? Thank you in advance!

 採用された回答

Star Strider
Star Strider 2015 年 1 月 21 日

6 投票

Yes. You need to use the ‘~’ (in English, tilde) to suppress the outputs you don’t want. So to get only ‘D’, call the function as:
[~,D] = myfun(1,1,1)

3 件のコメント

Alessandro Mogavero
Alessandro Mogavero 2020 年 9 月 16 日
Is there a way to do this inline? Something like:
myfun(1,1,1){2}
though I tried this and it does not work.
ajeet sahu
ajeet sahu 2021 年 8 月 8 日
Suppose I have a function with 10 outputs and I want the only 5th output so Do I have to suppess output of all other 9 to get only 5th?Is there any other simple command to do that?
Star Strider
Star Strider 2021 年 8 月 8 日
@ajeet sahu It would llikely be necessary to suppress at least the first 4, then assign the fifth.
.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeArgument Definitions についてさらに検索

質問済み:

2015 年 1 月 21 日

コメント済み:

2021 年 8 月 8 日

Community Treasure Hunt

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

Start Hunting!

Translated by