在Matlab中抑制输出变量 [英] suppressing output variables in matlab

查看:212
本文介绍了在Matlab中抑制输出变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Matlab中使用具有多个输出的函数,但只对其中一个输出感兴趣.我想抑制其他输出变量(即避免将它们返回并放置到内存中).例如,使用max函数:

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

有什么方法可以调用该函数,以便不返回output1?如果有的话,相对于上面的计算,它是否提供任何内存优势,但立即调用clear output1从内存中删除output1?

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?

感谢您的帮助.

推荐答案

使用波浪号:

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

我怀疑是否会有很多内存优势(除了诸如分配输出变量之类的文书工作之外),因为该函数将完全运行并分配所有需要的东西.这样,您就不会得到该值,并且max函数范围内的第一个输出变量的值将被垃圾收集.

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.

这篇关于在Matlab中抑制输出变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆