检查向量是否只包含零的“MATLAB方法”是什么,以便将其计算为标量而不是向量如果我运行此代码:

vector = zeros(1,10)

%the "1" represents a function that returns a scalar
if 1 && vector == 0   %this comparision won't work
    'success'
end

我知道错误:
??? 和的操作数&&
操作员必须可转换为
逻辑标量值。

最佳答案

使用all

vector = zeros(1,10)
if 1 && all(vector == 0)   %this comparision will work
    'success'
end

10-06 12:54
查看更多