필터 지우기
필터 지우기

Accessing to the position stored in a variable

조회 수: 1 (최근 30일)
Mohsen  Davarynejad
Mohsen Davarynejad 2011년 12월 10일
Suppose I have a matrix, A=rand(5,5) and an array, b=[2,3]. How can I extract the A(2,3) element? I know a simple solution is A(b(1), b(2)), but the problem is that I may end up with a high dimensional A matrix and I do not want to write something like: A(b(1), b(2), b(3),…., b(n)).

채택된 답변

Walter Roberson
Walter Roberson 2011년 12월 10일
The below does not look like much, but it uses a powerful MATLAB facility:
t = num2cell(b);
A(t{:})
  댓글 수: 1
Mohsen  Davarynejad
Mohsen Davarynejad 2011년 12월 10일
Many thanks Walter, It's perfectly matches what I was looking for.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by