필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
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 CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by