开发者

Matlab matrix ones elements checking

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜