Change sequence of consecutive trues to falses, in logical array
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Enrico Gambini
le 13 Oct 2022
Modifié(e) : Bruno Luong
le 13 Oct 2022
Hello guys!
I would like to find a fast procedure to change from true to false the consecutive trues in a logical array excluding only the first and the last true in the sequence.
For instance:
x=[true;false;false;true;true;true;true;true];
Desired output array should be:
output=[true;false;false;true;false;false;false;true];
Hope the question is clear.
Thank you!
0 commentaires
Réponse acceptée
Bruno Luong
le 13 Oct 2022
Modifié(e) : Bruno Luong
le 13 Oct 2022
x=[true;false;false;true;true;true;true;true;false;true]'
x & ~([false,x(1:end-1)]&[x(2:end),false])
0 commentaires
Plus de réponses (1)
Chunru
le 13 Oct 2022
x=[true;false;false;true;true;true;true;true]'
output = x;
dx = diff(x(1:end-1))
output1 = output(2:end-1);
output1(output1 & (dx==0)) = false;
% Desired output array should be:
output(2:end-1) = output1;
output
% Desired
[true;false;false;true;false;false;false;true]'
1 commentaire
Voir également
Catégories
En savoir plus sur Multidimensional Arrays 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!