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

1 Ansicht (letzte 30 Tage)
JL
JL am 28 Mai 2020
Kommentiert: JL am 28 Mai 2020
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];

Akzeptierte Antwort

Cris LaPierre
Cris LaPierre am 28 Mai 2020
ind = A(:,2)>=47;
B = A(ind,:);
C = A(~ind,:);
  3 Kommentare

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by