Find out if X out of Y elements of an array are true
Mostra commenti meno recenti
I have an array of 5 elements. The array is updated at any index (1,2,3,4,5) in each simulation time to a value TRUE or FALSE. In the next function, I should check if 4 out of 5 elements including the last updated element of the array are TRUE. Is there a way to check this?
Risposta accettata
Più risposte (1)
Arvind Sathyanarayanan
il 31 Mag 2019
Modificato: Arvind Sathyanarayanan
il 31 Mag 2019
You can do something like this :
X=sum(Array(:) == 1);
if X>=4
disp('4 or more elements are true')
end
3 Commenti
A VP
il 1 Giu 2019
Jos (10584)
il 1 Giu 2019
Logically, when one element changes at a time, (let's say, the k-th), the condition that 4 out of 5 are ture, is met can only happen when that element has become true. So, logically, that check is not really necessary ...
A VP
il 3 Giu 2019
Categorie
Scopri di più su Data Type Identification in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!