フィルターのクリア

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)
  1 件のコメント
Sahar abdalah
Sahar abdalah 2015 年 6 月 5 日
thanks Mr Azzi

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by