Reputation: 333
does it exist a function built-in in matlab that checks if a column is all composed of ones? If it doesn't exist, there are some ways to build a function that work to achieve that porpouse?
Upvotes: 1
Views: 58
Reputation: 34601
all(A==1)
should return true
if it's composed of only 1
s. Note that if you have any floating point precision errors, you should use all( abs(A-1) < eps )
.
Upvotes: 6
Reputation: 14498
If A is a column vector:
A=[1 1 1 1]';
You could check like this:
sum(A==1)==length(A)
ans =
1
Upvotes: 0
Reputation: 11810
You can compare all entries of a column to 1 and sum the result
if sum(A(:,1)~=1)==0
% all ones
else
% not all ones
end
Upvotes: 0