【发布时间】:2012-06-02 09:26:54
【问题描述】:
我在 Matlab 中使用具有多个输出的函数,但我只对其中一个输出感兴趣。我想抑制其他输出变量(即避免将它们返回并放入内存)。例如,使用 max 函数:
[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?
感谢您的帮助。
【问题讨论】:
-
@Amro 唯一的区别似乎是提到了性能考虑,尽管据我所知没有。
-
@reve_etrange:我想如果你真的想避免不必要的计算,你将不得不设计你的函数来返回
varargout参数,并重写它只在传递了足够的输出参数时才进行计算(由nargout值确定) -
@Amro 幸运的是,这种方法并不困难。不过,太糟糕了,JIT 编译器似乎是一个很好的地方。
标签: matlab syntax return-value