Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

Is there a way of scaling up using the A(i) to access elements for arrays of 3 or more dimensions?

1 visualización (últimos 30 días)
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 comentario
Stephen23
Stephen23 el 4 de Ag. de 2016
"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.

Respuestas (1)

Walter Roberson
Walter Roberson el 4 de Ag. de 2016
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))

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by