MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   如何在MATLAB中检查向量是否仅包含零? (https://www.labfans.com/bbs/showthread.php?t=23450)

poster 2019-12-10 20:41

如何在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 我得到错误:
[INDENT] ??? ||的操作数和&&运算符必须可转换为逻辑标量值。

[/INDENT]
[B]回答:[/B]

all使用:

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

[url=https://stackoverflow.com/questions/2873747]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 15:02

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.