Hello,
From an arbitrary matrix I want to extract n elements when I have 2 arrays of lenth n, one containing the row indices and 1 containing the column indices of the desired elements.
For effeciency I would like to avoid a for loop. Is this possible?
Thanks!

댓글 수: 2

Richard
Richard 2012년 5월 2일
could you provide an example?
Erik de Boer
Erik de Boer 2012년 5월 2일
Sure
Say I have a matrix A =
[3 6 2
5 1 3
4 7 8]
Row vector R = [1 2 3] and column vector C = [3 1 1]
Then I want to etract the elements [1,3],[2,1],[3,1] and arrive at
ans = [2 5 4]
Walter Robertson's aswer does exactly that. Thanks!

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

 채택된 답변

Walter Roberson
Walter Roberson 2012년 5월 2일

2 개 추천

YourMatrix( sub2ind( size(YourMatrix), Rows, Columns ) )

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by