MATLAB Answers

hey yo
0

Splitting a matrix into submatrices by value

hey yo
さんによって質問されました 2018 年 10 月 11 日
最新アクティビティ hey yo
さんによって コメントされました 2018 年 10 月 11 日
Hello, I have a 10000x3 matrix called A. The 3rd column of the matrix consists of 0s and 1s. I want to create 2 submatrices where A1 collects all rows of A that has a 1 in the 3rd column. A2 should collect the rest of the columns. How can I do that? Thanks!

  2 件のコメント

Give short example question is not clear . Give an example.
if true
A= [1 2 0; 3 4 0; 4 5 1; 4 7 0; 5 5 1]
end
I want to create
if true
A1=[4 5 1; 5 5 1] and A2=[1 2 0; 3 4 0; 4 7 0]
end
Now suppose that I have thousands of rows. How can I split the matrix A based on the 3rd column values?

サインイン to comment.

1 件の回答

Mischa Kim
Answer by Mischa Kim
on 11 Oct 2018
Edited by Mischa Kim
on 11 Oct 2018
 Accepted Answer

Something like this?
A = [2 3 0 3;...
3 2 1 3;...
2 2 1 2]
A =
2 3 0 3
3 2 1 3
2 2 1 2
A1 = A(A(:,3)==1,:)
A1 =
3 2 1 3
2 2 1 2
A2 = A(A(:,3)==0,:)
A2 =
2 3 0 3

  1 件のコメント

Excellent! Thank you.

サインイン to comment.



Translated by