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!