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

1 visualización (últimos 30 días)
JL
JL el 28 de Mayo de 2020
Comentada: JL el 28 de Mayo de 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];

Respuesta aceptada

Cris LaPierre
Cris LaPierre el 28 de Mayo de 2020
ind = A(:,2)>=47;
B = A(ind,:);
C = A(~ind,:);
  3 comentarios

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by