Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
Is there a way of scaling up using the A(i) to access elements for arrays of 3 or more dimensions?
조회 수: 1 (최근 30일)
이전 댓글 표시
If I have an array A that is 5x5 I can access each element either by A(x,y) where x and Y are from 1 to 5 or as A(i) where i is from 1 to 25. if A is a 5x5x10 I can use A(i,1) for the first 25 but not A(i,2) for the next group of 25.
Why is that? Other than calculating my own indices, is there a way of scaling up using the A(i) or A(i,n) to 3 or more dimensions?
Thank you
댓글 수: 1
Stephen23
2016년 8월 4일
"if A is a 5x5x10 I can use A(i,1) for the first 25"
I have never heard of this, nor does not work for me (MATLAB 2012b):
>> A = rand(5,5,10);
>> A(25,1)
Index exceeds matrix dimensions.
>> A(6,1)
Index exceeds matrix dimensions.
답변 (1개)
Walter Roberson
2016년 8월 4일
I just tested in R2016a and R2012a, and you can not use A(i,1) to access the first 25 when i > 5.
A = rand(5,5,10);
A(6,1) %an error
Linear indexing can only be used with a single subscript.
You should be considering using
A25 = reshape(A, 25, []);
and then you could use A25(7,3) for example which would correspond to the original A(2,2,3) as long as you are only reading the data (it would not "alias" the original array, so assigning to A25(7,3) would not change A(2,2,3))
댓글 수: 0
이 질문은 마감되었습니다.
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!