How can I get the elements from a matrix and use them as the coordinates in another matrix

조회 수: 1 (최근 30일)
I have a matrix
W=[1 3 4 1
1 2 3 1
1 2 4 1]
and I want to get the values of another matrix
C=[0 3 7 8
3 0 1 4
7 1 0 2
8 4 2 0].
That is, I want to take firstly the values of C which exist in (1,3) position, (3,4) position and (4,1) position (the first row of W), i.e. 7,2 and 8 respectively in matrix C and the sum of these values (18). The same indeed for all the rows.

채택된 답변

Matt J
Matt J 2020년 2월 10일
편집: Matt J 2020년 2월 10일
D = C( sub2ind( size(C), W(:,1:end-1), W(:,2:end) ) ),
sum(D,2)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Point Cloud Processing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by