MATLAB Answers

Translated by

このページのコンテンツは英語から自動翻訳されています。自動翻訳をオフにする場合は「<a class="turn_off_mt" href="#">ここ</a>」をクリックしてください。

0

Split array into cell arrays of different size

lightroman さんによって質問されました 2017 年 11 月 1 日
最新アクティビティ Cedric Wannaz
さんによって 編集されました 2017 年 11 月 2 日
I have an array that I am trying to divide into different lengths arrays. The array is 750000 values or so long so I needed an efficient way. I want to start the next array when pattern finishes or begins to start over.
An example would be
A = [5 19 43 28 5 19 43 5 19 43 28 5 19 5 19 43]
I want the result to be something like
Result = {5 19 43 28} {5 19 43} {5 19 43 28} {5 19} {5 19 43}
However, it can also be a longer pattern, [5 19] is how I know the pattern restarts because these values only occur at the beginning of each data set.

  0 件のコメント

サインイン to comment.

1 件の回答

回答者: Cedric Wannaz
2017 年 11 月 1 日

>> seqs = mat2cell( A, 1, diff( [strfind(A, [5,19]), numel(A)+1] ))
seqs =
1×5 cell array
{1×4 double} {1×3 double} {1×4 double} {1×2 double} {1×3 double}

  2 件のコメント

lightroman 2017 年 11 月 1 日
I get an error saying PATTERN must be a string or cell array of strings, evaluating arg list element 1 .... element 3.
Any idea why? Using same code as I have posted with your solution.
Cedric Wannaz
2017 年 11 月 2 日
Which version of MATLAB are you using? STRFIND has been working with numeric array for a long time.
seqs = mat2cell( A, 1, diff( [find(A(1:end-1)==5 & A(2:end)==19), numel(A)+1] ))
and if you need to be more flexible about the size of start patterns, we can generalize the call to FIND, but for this I'll need to know your version of MATLAB.

サインイン to comment.



Translated by