searching first two consecutive ones and set to 0
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Arif Hoq
le 25 Fév 2022
Modifié(e) : Arif Hoq
le 25 Fév 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 commentaires
Jan
le 25 Fév 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)
Voir également
Catégories
En savoir plus sur Statistics and Machine Learning Toolbox 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!