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 件のコメント
JL
JL 2020 年 5 月 28 日

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by