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)
.
精彩评论