Access element of ND array specified by another array?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Rohit Gupta
am 7 Jun. 2018
Kommentiert: Rohit Gupta
am 7 Jun. 2018
I have a N1 x N2 x N3 dimension Tensor T. Plus I have a 1 x 3 array a = [a1 a2 a3]. How do I access element T(a1,a2,a3). Is there any way to do this for N dimension.
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 7 Jun. 2018
Bearbeitet: Walter Roberson
am 7 Jun. 2018
acell = num2cell(a);
T(acell{:})
There are also ways to calculate the location as a linear index based upon size(T)
Ts = size(T):
La = length(a);
Ts(end+1:La) = 1;
idx = a(1) + sum((a(2:end)-1) .* cumprod(Ts(1:La-1)))
T(idx)
... if I didn't miss something.
Weitere Antworten (1)
Siehe auch
Kategorien
Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!