division of a single column matrix

i have a single column matrix A=0 0 0 1 1 1 1 0 0 0 0 2 2 2 2 0 0 0 0 1 1 1 now i have to divide this in to several matrices such whenever 0 changes to 1 or 2 i want a new matrix in this case A1= 1 1 1 1 0 0 0 0; A2=2 2 2 2 0 0 0 0 ;A3= 1 1 1 which are also single column matrices ............using for loop

1 件のコメント

Oleg Komarov
Oleg Komarov 2011 年 5 月 16 日
See my double edited answer in the previous post.

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

回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2011 年 5 月 16 日

0 投票

in this case
A = A(:);
I = cumsum([0;diff(A)]~=0 & (A == 1 | A == 2));
out = arrayfun(@(x)A(I==x),1:max(I),'un',0);
Dear bilhan! I think it is necessary to remove the question. See commentary by Oleg Komarov

4 件のコメント

Oleg Komarov
Oleg Komarov 2011 年 5 月 16 日
This a duplicate post and the op asked a loop solution: http://www.mathworks.com/matlabcentral/answers/7497-dividing-a-column-matrix-based-on-the-no
Andrei Bobrov
Andrei Bobrov 2011 年 5 月 16 日
Hi Oleg, i'm to blame, did not notice.
Oleg Komarov
Oleg Komarov 2011 年 5 月 16 日
You can add your answer to the other post. Multiple interpretations are always useful.
Andrei Bobrov
Andrei Bobrov 2011 年 5 月 16 日
well

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

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

質問済み:

2011 年 5 月 16 日

Community Treasure Hunt

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

Start Hunting!

Translated by