how to create 2 matrices from 1 matrix depending on values 0 & 1, displayed in first column of 1st matrix?

1 回表示 (過去 30 日間)
I have a matrix like this
A = [1 | 3 4 5 6 7 8 9;
0 | 4 5 6 9 1 4 6;
1 | 3 1 5 1 7 1 9;
0 | 6 5 6 1 1 4 1];
first column has values 0 & 1
I want to create new matrices from the index of first column i.e. for 1 above will be like
B = [3 4 5 6 7 8 9;
3 1 5 1 7 1 9];
and for value 0
C = [4 5 6 9 1 4 6;
6 5 6 1 1 4 1];
can some one please guide me how to achieve this in Matlab, been trying a lot to do but the C coding aspects are not helping me much.
Please some one? thanks!

採用された回答

Matt Fig
Matt Fig 2012 年 12 月 2 日
編集済み: Matt Fig 2012 年 12 月 2 日
Now I think I see what you did. You probably did not realize that the | symbol evaluates to logical OR when someone copies and pastes your code.... So leave that out, it is just confusing...
A = [1 3 4 5 6 7 8 9;
0 4 5 6 9 1 4 6;
1 3 1 5 1 7 1 9;
0 6 5 6 1 1 4 1]
A_ones = A(A(:,1)==1,2:end)
A_zeros = A(~A(:,1),2:end)
  1 件のコメント
zaxven
zaxven 2012 年 12 月 2 日
have used '|' symbol to only differentiate as 1st column. but anyways thanks a ton matt!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLinear Algebra についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by