indexing and performing operations in matrix

조회 수: 1 (최근 30일)
cgo
cgo 2015년 11월 11일
댓글: cgo 2015년 11월 11일
I have an nx2 matrix A. I also have an interaction matrix of A, which looks like this:
interact = [1 2;
1 4;
1 5;
2 1;
2 3;
3 4;
3 6]
These numbers are just the index. I want to perform the following operation: (A(1,:) - A(2,:))+(A(1,:)-A(4,:))+ (A(1,:)-A(5,:)), then store result into some matrix R(1,:)
Likewise, A(2,:) - A(1,:) + A(2,:) - A(3,:) = R(2,:) etc.
How do I do this?
  댓글 수: 2
Walter Roberson
Walter Roberson 2015년 11월 11일
Could you confirm that all of the entries with the same value in column 1 should be treated as a group? And if that is the case, then what should happen if the entrees are not consecutive, such as if there was another entry beginning with 1 after the [3 6] ?
cgo
cgo 2015년 11월 11일
I got it already!!!
for val=1:n
iv=interact(ismember(interact(:,1),val),2)
repmat(A(val,:),size(iv,1),1)
A(iv,:)
end
Thanks for your help though.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by