matlab - 如何确定输出是否被忽略 ~

标签 matlab function reflection

<分区>

在 Matlab 中,您可以忽略带有以下 syntax 的输出:

[~, ixMax] = max(foo);

我有一个函数,带有签名

[out, out1, out2, out3] = function foo(in1, in2, in3)

out1out2out3 是可选输出,每个都只在非常特殊(不寻常)的情况下才需要。 Foo 的计算量很大,out1/out2/out3 的计算量更大,但是依赖于中间层foo 生成的状态。如果调用者使用 ~,我希望能够避免计算 out1/out2/out3忽略它们。我如何在 foo 的定义中检查它?

最佳答案

它不会加速这个过程。 ~ 是读者告诉他您不需要这些输出的一种方式。它还节省了该变量的内存使用量。

Matlab documentation说:

However, some functions return results that use much more memory. If you do not need those variables, they waste space on your system.

所以它不会提高性能,因为这些值无论如何都是在内部计算的。

Yair M. Altman 的Accelerating MATLAB Performance: 1001 tips to speed MATLAB programs 一书说(第 187 页):

enter image description here

但是,如果不使用~,如果需要第一个输出,用户只需删除~即可获得计算时间和括号,以及写作。

out = function foo(in1, in2, in3)

关于matlab - 如何确定输出是否被忽略 ~,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46667883/

相关文章:

java - 静态检查 Java 应用程序是否存在链接错误

image - MATLAB M x N x 24 数组到位图

matlab - 如何绘制这个?

c++ - 我的 C++ 代码中的字母计数器工作不正常

java - 反射获取特定类中带注释的所有方法

swift - 我想将 RawRepresentable 的 rawValue 作为 Any 返回,但我只将它作为 Any 接收

c++ - MATLAB MEX C++ 文件编译错误 g++ command not found

matlab - 在 Matlab 中减去两个向量

javascript - jQuery 双动画组合

c++ - 什么是真正的虚函数?