matlab - Matrix containing values of another matrix -
This is my problem: For example, I have a matrix of order 4 (knowing that I have a very large matrix Is):
A = [3 4 5 2; 1 2 4 6; 3 4 8 7; 2 4 3 7]
And in a matrix B, the index rows and columns of matrix A are:
B = [2 3 4 1; 4 3 2 1; 3 2 1 4; 4 2 3 1; 1 2 3 4]
I search for a vector C (5,1), such as:
c (1,1) = A (b (1,1, b, 1,2) + a (b (1,2), b (1,3)) + a (b (1,3), b (1,4)) = a 2, 3) + A (3,4) + A (4,1) c (2,1) = a (4,3) + a (3,2) + a (2,1) c (3.1) ) = A (3,2) + A (2,1) + A (1,4) C (4,1) = A (4,2) + A (2,3) + A (3,1) C (5,1) = A (1,2) + A (2,3) + A (3,4)
then
C = [13; 8; 7; 1 1; 15]?
I want to find a way to make it in a clean and customized way. Thank you very much
using sub2ind
to convert you to linear index Can
szA = size (A); C = A (Sub 2 Ind (SAJA, B (:, 1), B (:, 2)) ... (SubZind (SJA, B (:, 2), B (:, 3))) + . A (Sub-Bound (SSAA, B (:, 3), B (:, 4)));
Comments
Post a Comment