フィルターのクリア

how to combine to matrix with the same rows and different columns

2 ビュー (過去 30 日間)
Maryam Hamrahi
Maryam Hamrahi 2016 年 12 月 23 日
コメント済み: Maryam Hamrahi 2016 年 12 月 23 日
I have matrix A with n rows and three columns, matrix B with n rows and one column. For instance, matrix A and B could be as follows:
A= [1 4
3 6
4 7
1 3
5 2
7 9]
B=[1
2
2
3
2
5]
As you see, matrix A and B have the same number of rows. I would like to produce matrix C from matrix A, but only rows which are “2” in matrix B.
C=[3 6
4 7
5 2]
It would be appreciated if you could give me some ideas for solving this problem.
Thanks

採用された回答

Walter Roberson
Walter Roberson 2016 年 12 月 23 日
A= [1 4
3 6
4 7
1 3
5 2
7 9];
C = A(B == 2, :);
  1 件のコメント
Maryam Hamrahi
Maryam Hamrahi 2016 年 12 月 23 日
Thank you very much Walter Roberson.
your help is really appreciated.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by