How can transform matrix???

1 Ansicht (letzte 30 Tage)
Sahar abdalah
Sahar abdalah am 5 Jun. 2015
Kommentiert: Sahar abdalah am 5 Jun. 2015
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

Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 5 Jun. 2015
Bearbeitet: Azzi Abdelmalek am 5 Jun. 2015
[n,m]=size(A)
C=reshape(B(sub2ind([n,m],(1:n)'*ones(1,m),A)),n,m)

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by