How can transform matrix???

조회 수: 1 (최근 30일)
Sahar abdalah
Sahar abdalah 2015년 6월 5일
댓글: Sahar abdalah 2015년 6월 5일
Hello everyone, I have two matrix A and B.
A= [1 2 3 4 5 6 7 8 9 10;
2 1 3 4 5 6 7 8 9 10;
2 3 1 4 5 6 7 8 9 10;
3 2 1 4 5 6 7 8 9 10;
4 1 3 2 5 6 7 8 10 9];
B= [1 628 819 124 660 60 639 224 704 133;
351 320 2 477 82 60 548 905 699 143;
715 475 892 324 37 543 402 298 676 197;
4 5 898 799 480 604 188 812 112 693;
5 79 993 170 182 706 265 140 812 390];
The matrix A contains the indices of the matrix B and now I want to build a matrix C corresponding to the values in matrix B according to the indices of the matrix A. For example the matrix C will come following:
C=[1 628 819 124 660 60 639 224 704 133;
320 351 2 477 82 60 548 905 699 143;
475 892 715 324 37 543 402 298 676 197;
898 5 4 799 480 604 188 812 112 693;
170 5 993 79 182 706 265 140 390 812];
please help me how can I implement this program?? thanks in advance

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2015년 6월 5일
편집: Azzi Abdelmalek 2015년 6월 5일
[n,m]=size(A)
C=reshape(B(sub2ind([n,m],(1:n)'*ones(1,m),A)),n,m)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by