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

1 vue (au cours des 30 derniers jours)
JL
JL le 28 Mai 2020
Commenté : JL le 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];

Réponse acceptée

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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by