Info
Questa domanda è chiusa. Riaprila per modificarla o per rispondere.
Is there a way of scaling up using the A(i) to access elements for arrays of 3 or more dimensions?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commento
Stephen23
il 4 Ago 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.
Risposte (1)
Walter Roberson
il 4 Ago 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))
0 Commenti
Questa domanda è chiusa.
Vedere anche
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!