Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
510 views
in Technique[技术] by (71.8m points)

syntax - suppressing output variables in matlab

I am using a function with multiple outputs in Matlab, but am only interested in one of the outputs. I would like to suppress the other output variables (i.e. avoid them being returned and placed into memory). For example, with the max function:

[output1 output2] = max(matrixA, [], 1);
% output1 returns the maximum, which i'm not interested in
% output2 returns the index of the maximum, which i *am* interested in

Is there any way to call the function so that output1 is not returned? And if there is, does it offer any memory advantage over calculating as above but immediately calling clear output1 to remove output1 from the memory?

Thanks for your help.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Use the tilde:

[~, output2] = max(matrixA, [], 1);

I doubt there would be much memory advantage (apart from clerical stuff like allocating output variables, etc.)) since the function will run completely and allocate all that it needs to. This way, you just don't get the value, and the value of the first output variable in the scope of the max function will be garbage-collected.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...