Splitting matrix A in Matrix B and C based on column 2 values

조회 수: 1 (최근 30일)
JL
JL 2020년 5월 28일
댓글: JL 2020년 5월 28일
I have matrix A
A = [1 55 14 1 1 1
2 55 14 1 1 1
3 55 14 1 1 1
4 35 14 1 1 1
5 35 13 1 1 2
6 35 12 1 1 2
7 35 11 2 2 3
8 35 11 2 2 3
9 35 9 2 2 3
10 35 8 2 2 3
11 35 8 3 3 4
12 35 8 3 3 4
13 35 8 4 1 5
14 35 9 4 1 5
15 33 8 5 4 4
16 32 8 5 4 4
17 31 8 5 4 4
18 30 8 5 3 4];
I want to split A into B and C using column 2. If column 2 is >= 47, rows moves into matrix B while if column 2 is <47, moves into matrix C
B = [1 55 14 1 1 1
2 55 14 1 1 1
3 55 14 1 1 1];
C = [4 35 14 1 1 1
5 35 13 1 1 2
6 35 12 1 1 2
7 35 11 2 2 3
8 35 11 2 2 3
9 35 9 2 2 3
10 35 8 2 2 3
11 35 8 3 3 4
12 35 8 3 3 4
13 35 8 4 1 5
14 35 9 4 1 5
15 33 8 5 4 4
16 32 8 5 4 4
17 31 8 5 4 4
18 30 8 5 3 4];

채택된 답변

Cris LaPierre
Cris LaPierre 2020년 5월 28일
ind = A(:,2)>=47;
B = A(ind,:);
C = A(~ind,:);
  댓글 수: 3

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by