How to do this below?
1 回表示 (過去 30 日間)
古いコメントを表示
Suppose you have a binary sequence:
a = [0 0 1 1 1 0 0 1 1 1 1 0 0 0];
And, how can you abtain a sequence b from a?
b = [0 0 3 0 0 0 0 4 0 0 0 0 0 0];
That is, place the sum of the consequtive ones at the first location of the consecutive ones.
And, make zeros for all the other locations of ones.
Thank you,
0 件のコメント
採用された回答
Voss
2024 年 2 月 6 日
One way:
a = [0 0 1 1 1 0 0 1 1 1 1 0 0 0]
b = zeros(1,numel(a));
s_idx = strfind([0 a],[0 1]);
e_idx = strfind([a 0],[1 0]);
b(s_idx) = e_idx-s_idx+1;
b
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Characters and Strings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!