필터 지우기
필터 지우기

Indexing high dimension elements from a N-D matrix

조회 수: 1 (최근 30일)
Junhong YE
Junhong YE 2014년 5월 28일
댓글: Matt J 2014년 5월 28일
Hi, all,
I met a problem when I was trying to index the third dimension elements of a 3-dim matrix, i.e.
A=rand(10,10,10);
B=A(1,1,:);
, I found B was not a vector as I expected, but rather, a 1-by-1-by-10 array. But A(:,1,1) and A(1,:,1) return a column and row vector respectively.
I wonder why MATLAB is designed in this way and how to obtain what I want ?
I know a workaround is use squeeze(A(1,1,:)), which ignores the singleton dimensions. Is there any other more direct way?
Thanks.
  댓글 수: 1
Matt J
Matt J 2014년 5월 28일
I wonder why MATLAB is designed in this way
As you already pointed out, A(:,1,1) and A(1,:,1) are not the same shape and have singleton dimensions where you provided singleton subscripts. If that makes sense to you, why should A(1,1,:) obey a different rule?

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

채택된 답변

Matt J
Matt J 2014년 5월 28일
B(1:10)=A(1,1,:)

추가 답변 (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