Change sequence of consecutive trues to falses, in logical array
    6 ビュー (過去 30 日間)
  
       古いコメントを表示
    
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 件のコメント
採用された回答
  Bruno Luong
      
      
 2022 年 10 月 13 日
        
      編集済み: Bruno Luong
      
      
 2022 年 10 月 13 日
  
      x=[true;false;false;true;true;true;true;true;false;true]'
x & ~([false,x(1:end-1)]&[x(2:end),false])
0 件のコメント
その他の回答 (1 件)
  Chunru
      
      
 2022 年 10 月 13 日
        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]'
参考
カテゴリ
				Help Center および File Exchange で Matrix Indexing についてさらに検索
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


