0

I have a function called f(x,y), which returns 1 when both x = -1 and y = 1, and 0 otherwise.

I want to apply it on every pair of the same column elements of a matrix. I want to know if I have to repeat it the other way? or does it work the same for f(y,x)? I mean does it return 1 if one of the elements is -1 and the other is 1 anyway or it has to be in order?

4

1 回答 1

4

这取决于函数f是如何定义的。

  • 如果它相对于输入是对称的,即“其中一个”需要-1和“另一个” 1,则它可以在不改变反向输入的情况下工作。
  • 如果函数被定义为“第一个”输入必须是-1“第二个”输入必须是1- 切换参数顺序时结果可能会不同。

例如,这是定义的“对称”方式f

function out = f(x,y)
  out = ~(x+y);
end

这是一种“不对称”的方式:

function out = f(x,y)
  out = (x == -1) && (y == 1);
end
于 2018-07-29T13:35:16.910 回答