Avoiding cross product for accessing the matrix

조회 수: 1 (최근 30일)
Junaid
Junaid 2011년 11월 26일
Let say I have matrix A = magic(10). I want to get few selected values of A. Let say A(5,10), A(6,10), A(5,5). If for row I have vector r = [5 6 5] and c = [10 10 5], Then when I do
A(r,c), instead of three values I get 3x3. it is due to fact that for each value in r is paired with each value in c. How can I avoid this. I want that for the first value of r take first value of c and so on.
Actually I want to calculate the time for function, therefore, I have to take minimum instruction to compute.
Sorry for any inconvenience caused.

채택된 답변

Oleg Komarov
Oleg Komarov 2011년 11월 26일
pos = sub2ind(size(A), r,c)
A(pos)
  댓글 수: 3
Daniel Shub
Daniel Shub 2011년 11월 26일
You should ask this as another question.
Andrei Bobrov
Andrei Bobrov 2011년 11월 26일
Hi Oleg! Finally then, you're back!

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by