Borrar filtros
Borrar filtros

How can transform matrix???

1 visualización (últimos 30 días)
Sahar abdalah
Sahar abdalah el 5 de Jun. de 2015
Comentada: Sahar abdalah el 5 de Jun. de 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

Respuesta aceptada

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

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by