searching first two consecutive ones and set to 0
2 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Arif Hoq
2022 年 2 月 25 日
編集済み: Arif Hoq
2022 年 2 月 25 日
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 件のコメント
Jan
2022 年 2 月 25 日
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)
参考
カテゴリ
Help Center および File Exchange で Statistics and Machine Learning Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!