필터 지우기
필터 지우기

Extracting multiple matrix from a single matrix

조회 수: 1 (최근 30일)
Vishnu Kant
Vishnu Kant 2018년 9월 8일
답변: Walter Roberson 2018년 9월 8일
I have a matrix(type double) similar to the following example:
X = [ 23 3 5 1;
21 45 8 1;
65 56 7 1;
71 42 4 2;
45 91 5 2;
34 6 1 3;
87 37 8 3;
23 3 5 3]
Based on the element of the fourth column I want to get 3 matrix from the above matrix like the following example;
A=[ 23 3 5 1;
21 45 8 1;
65 56 7 1; ]
B =[ 71 42 4 2;
45 91 5 2; ]
C =[ 34 6 1 3;
87 37 8 3;
23 3 5 3;]
Basically I want to seprate all the 1s,2s and 3s of the fourth column into another matrix. How can I do it in the Matlab!

채택된 답변

Walter Roberson
Walter Roberson 2018년 9월 8일
A = X( X(:,4) == 1, :);
B = X( X(:,4) == 2, :);
C = X( X(:,4) == 3, :);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by