登录论坛

查看完整版本 : 如何在MATLAB中检查向量是否仅包含零?


poster
2019-12-10, 20:41
检查向量是否仅包含零的“ 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

更多&回答... (https://stackoverflow.com/questions/2873747)