search for a value in one matrix in another matrix

조회 수: 3 (최근 30일)
Berfin Çetinkaya
Berfin Çetinkaya 2022년 3월 29일
댓글: Voss 2022년 3월 30일
Hi everybody
Matrix A:
16 14 12 10 18
Matrix B:
2
3
5
4
1
new matrix :
2 14
3 12
5 18
4 10
1 16
For example, since 2 is written in matrix B, it prints the second row value in A next to 2 in the new matrix.
I need such a matrix. Could you help?
Thank u

채택된 답변

Voss
Voss 2022년 3월 29일
% Matrix A:
A = [16 14 12 10 18];
% Matrix B:
B = [2; 3; 5; 4; 1];
% new matrix :
new_matrix = [B A(B).']
new_matrix = 5×2
2 14 3 12 5 18 4 10 1 16
  댓글 수: 5
Berfin Çetinkaya
Berfin Çetinkaya 2022년 3월 30일
yes I meant that. Thanks a lot of.
Voss
Voss 2022년 3월 30일
Excellent. You're welcome!

댓글을 달려면 로그인하십시오.

추가 답변 (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