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) ….. condition.
all(x == 1)will return1if all the members are1.If you’d rather check the reverse, use
any(x ~= 1).