查看单个帖子
旧 2019-12-10, 20:41   #1
poster
高级会员
 
注册日期: 2019-11-21
帖子: 3,006
声望力: 66
poster 正向着好的方向发展
帖子 如何在MATLAB中检查向量是否仅包含零?

检查向量是否仅包含零的“ 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

更多&回答...
poster 当前离线   回复时引用此帖