Effacer les filtres
Effacer les filtres

How to compare two different columns with a value to check all have same values.

1 vue (au cours des 30 derniers jours)
Arsal15
Arsal15 le 17 Fév 2016
I have two columns with 15 rows and there value can be either all 0 or all 1 and I want to check after certain computation that there value is now 1 or not in order to terminate the computation.
Can you guide me ?

Réponses (1)

Sebastian Castro
Sebastian Castro le 18 Fév 2016
You could use the all function to perform a comparison with 1 for all elements.
For a single row, it would be
if all(x==1)
% Continue
end
For a 2-D array, the default is that the all function operates on each column. So, if you want to check all elements across both rows:
if all(all(x==1))
% Continue
end
Final note: If your values can only be 0 or 1, the condition x is sufficient instead of having to check the individual value x==1...
- Sebastian

Catégories

En savoir plus sur Animation dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by