Cutting a certain pattern from an array
古いコメントを表示
Hello everyone!
I have a simple question regarding deleting certain pattern from array. For example I have a random array
A=[1 2 3 4 5 6 0 0 0 0 1 2 3 4 5 6 7 8 9 10 0 0 0 0 ...]
I want to delete all fragments, built of four zeroes. So cut away all B=[0 0 0 0] from a 1d array.
How can I implement it?
採用された回答
その他の回答 (1 件)
>> A = [1,2,3,4,5,6,0,0,0,0,1,2,3,4,5,6,7,8,9,10,0,0,0,0];
>> B = [0,0,0,0];
>> +strrep(char(A),char(B),'')
ans =
1 2 3 4 5 6 1 2 3 4 5 6 7 8 9 10
2 件のコメント
Walter Roberson
2015 年 9 月 24 日
Hee, cute.
Works fine for non-negative integers up to 65535 but not in general.
Stephen23
2015 年 9 月 24 日
True. It is also more than 100x faster than the accepted solution :)
カテゴリ
ヘルプ センター および File Exchange で Calendar についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!