multiply values in different rows
2 ビュー (過去 30 日間)
古いコメントを表示
Hi!
I have three matrices.
first matrices :
A=
2 3 1 4
8 5 2 3
1 2 6 7
6 8 4 1
B=
0,1
0,5
0,4
0,2
C=
10
20
15
5
25
15
10
20
For example, look at the value in the first matrix for the cell that says 8 in matrix A. For example, it says 2 on top of 8. Since it writes 2, let it take the value of the 2nd row in B matrix. (A value of 0.5 is taken.)
Since 8 is written in matrix A, take the value written in 8th row from matrix C. (It takes the value 20.)
And multiply the received value of 0.5 by the value of 20.
Let it do this for all cells in matrix A.
new matrices=
10 10 2 3
5 8 1,5 2
7,5 8 0,5 2
Thank you for help.
0 件のコメント
採用された回答
DGM
2022 年 5 月 25 日
I'm going to guess that this is what you're after:
A = [2 3 1 4; 8 5 2 3; 1 2 6 7; 6 8 4 1];
B = [0.1; 0.5; 0.4; 0.2];
C = [10; 20; 15; 5; 25; 15; 10; 20];
output = B(A(1,:)).' .* C(A(2:end,:))
2 件のコメント
DGM
2022 年 5 月 25 日
I'm not sure what determines the number of output rows, but assuming it's 4:
A = [2 3 1 4; 8 5 2 3; 1 2 6 7; 6 8 4 1];
B = [0.1; 0.5; 0.4; 0.2];
C = [10; 20; 15; 5; 25; 15; 10; 20];
output = B(A(1,:)).*C(A(1,:));
output = repmat(output.',[4 1])
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Multidimensional Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!