フィルターのクリア

splitting a array at defined interval

1 回表示 (過去 30 日間)
strunack
strunack 2013 年 4 月 9 日
I have a array c of 276 elements. I want to split it into 3 separate array. The number of elements in each of these three array is within the array c itself.
vind=c(find(c>=10)) %gives me
vind =
45 45 183
I have to split the array c into three arrays with number of elements as 45, 45 and 183 respectively excluding the position of these three numbers. Pls suggest how it can be done.
with thanks

採用された回答

Cedric
Cedric 2013 年 4 月 9 日
編集済み: Cedric 2013 年 4 月 9 日
Alternatively:
loc = find(c >= 10) ;
vind = c(loc) ;
c(loc) = [] ;
out = mat2cell(c, 1, vind) ;
  1 件のコメント
strunack
strunack 2013 年 4 月 10 日
I accepted this answer, because its very logical, clean and simple way to split without any loop. I could do the same with loop but in a rather inefficient way than Azzi's answer. Thanks to him too.

サインインしてコメントする。

その他の回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 4 月 9 日
ii=1;
for k=1:numel(vind)
jj=vind(k)
out{k}=c(ii:jj)
ii=jj+1;
end
  1 件のコメント
Jan
Jan 2013 年 4 月 9 日
編集済み: Jan 2013 年 4 月 9 日
Please add some code for the pre-allocation also. Otherwise we have to answer corresponding question next week again. Thanks.
As far as I understand, the OP wants the part from ii to jj-1 only.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by