Change sequence of consecutive trues to falses, in logical array
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Enrico Gambini
am 13 Okt. 2022
Bearbeitet: Bruno Luong
am 13 Okt. 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 Kommentare
Akzeptierte Antwort
Bruno Luong
am 13 Okt. 2022
Bearbeitet: Bruno Luong
am 13 Okt. 2022
x=[true;false;false;true;true;true;true;true;false;true]'
x & ~([false,x(1:end-1)]&[x(2:end),false])
0 Kommentare
Weitere Antworten (1)
Chunru
am 13 Okt. 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 Kommentar
Siehe auch
Kategorien
Mehr zu Multidimensional Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!