searching first two consecutive ones and set to 0
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
VASUNDHARA V
am 25 Feb. 2022
Kommentiert: VASUNDHARA V
am 25 Feb. 2022
y=[1 1 1 1 1 1 1 1 1 1 1]
i want to search for first two consecutive ones everytime and allocate them 0
like this
y=[0 0 1 1 1 1 1 1 1 1 1]
0 Kommentare
Akzeptierte Antwort
Arif Hoq
am 25 Feb. 2022
Bearbeitet: Arif Hoq
am 25 Feb. 2022
try this:
y=[1 1 1 1 1 1 1 1 1 1 1];
idx=y(1:2);
b=find(y(idx));
if y(b)==1
y(b)=0;
end
disp(y)
3 Kommentare
Jan
am 25 Feb. 2022
This does not work, if y does not start ith two 1 values:
y=[0 0 1 1 1 1 1 1 1 1 1]
idx=y(1:2);
b=find(y(idx));
if y(b)==1
y(b)=0;
end
disp(y)
Siehe auch
Kategorien
Mehr zu Statistics and Machine Learning Toolbox 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!