开发者

Matlab matrix ones elements checking

开发者 https://www.devze.com 2023-03-01 17:25 出处:网络
Suppose I have a vector like x = [1 1 1 1 1 1]. Now I have to write an if condition, where I have to check whether x contains all its elements as ones or not. How can this be done?

Suppose I have a vector like x = [1 1 1 1 1 1].

Now I have to write an if condition, where I have to check whether x contains all its elements as ones or not. How can this be done?

I searched in matlab's help, but couldn't find any direct "command" to check such a condition. Also the size of my vector varies, so can't use something like x(1,1) == 1 && x(2,1) 开发者_JAVA百科..... condition.


all(x == 1) will return 1 if all the members are 1.

If you'd rather check the reverse, use any(x ~= 1).

0

精彩评论

暂无评论...
验证码 换一张
取 消