フィルターのクリア

Deleting repeating numbers from array

1 回表示 (過去 30 日間)
Bran
Bran 2018 年 9 月 21 日
編集済み: Stephen23 2018 年 9 月 21 日
I have a very long array of numbers consisting of 0's and 1's and I would like to delete sections where 0 is consecutively repeated thirty times or more. How would I go about this?

採用された回答

Stephen23
Stephen23 2018 年 9 月 21 日
編集済み: Stephen23 2018 年 9 月 21 日
Method one: regexprep:
A = [zeros(1,30),1,1,1,1,zeros(1,29),1,1,zeros(1,30)]; % fake data
Z = +regexprep(char(A),'\0{30,}','')
Method two: diff, find, and a loop:
Z = A;
D = diff([1,Z,1]);
B = find(D<0);
E = find(D>0);
X = find((E-B)>=30);
for k = X(end:-1:1)
Z(B(k):E(k)-1) = [];
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by