Matlab 未使用的输入符号详细信息

标签 matlab operators

Matlab R2009b introduced a new "operator" - ~ - 表示未使用的函数输出或输入。我对该实现有详细的疑问。 (调用所有 @Loren s。)

对于未使用的输入参数的值,函数会看到什么?

即如果我的函数定义为

myfunc(argOne, argTwo, argThree)

它的名字是这样的:

myfunc('arg', ~, 'arg')

nargin 是 2 还是 3? argTwo 是未定义的还是空的还是其他什么?

谢谢

最佳答案

~ 语法仅适用于函数定义的输入,不适用于函数调用的输入(如 this documentation page 中所讨论).换句话说,这个没问题:

function myfunc(argOne, ~, argThree)  %# Will do nothing with the second input
  %# Do stuff here
end

但是不是:

myfunc('arg', ~, 'arg');  %# Error city ;)

因此,调用函数时,只能使用左侧~:

[~, I] = sort([2 4 1 2 5 3]);  %# Sort the vector and keep only the index

关于Matlab 未使用的输入符号详细信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2002542/

相关文章:

javascript - 扩展脚本中的 OR 运算符

c++ - 如何让Boost::random和Matlab产生相同的随机数

matlab - lib Linear 的 50% 准确度问题

matlab - Matlab/CUDA : ocean wave simulation

matlab - 将指针移动到对象上 (MATLAB)

c++ - 重载的返回类型 >>

python - scipy.io.savemat 如何保存全局变量?

java - Java中 "<object>"运算符的含义

java - 比较运算符自定义对象java

javascript - Javascript "this"运算符如何处理范围?