How to keep TRUE if followed by FALSE but if TRUE is followed by TRUE, change the second TRUE to false?

I have an array of logic 1 and 0's.
If 1 is immediately followed by another 1, I want to change this second 1 to a 0.
trial_index = zeros(size(trial)+1);
for i = 1: length(trial)
if trial(i) == 1
strial_index(i) = 1;
else
trial_index(i) = 0;
end
if trial(i+1) == 1
trial_index(i+1) = 0;
end
end

 採用された回答

KSSV
KSSV 2021 年 3 月 30 日
a = round(rand(100,1)) ;
b = a ;
for i = 2:length(a)
if a(i-1)==1 && a(i)==1
b(i) = 0 ;
end
end

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Loops and Conditional Statements についてさらに検索

タグ

質問済み:

2021 年 3 月 30 日

コメント済み:

2021 年 3 月 30 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by