Use NxD array of indices to reference a D dimension array in matlab
2 次查看(过去 30 天)
显示 更早的评论
I have a matlab matrix full of indices (indx) which can be N rows and D columns (and varies from execution to execution). I also have an output array of D dimensions, output(D1,D2,..,D_D). For a given indx, for example if D=3, a row of indx might equal (1, 2, 3), and I'd like to index output(1,2,3)=k.
However, I am not sure of two things.
1. I don't know D beforehand, how can I access a D length set of indices in output?
2. If so, is there any way accessing all ordered n-tuples in indx for each of their associated entry in output?
For 1, a remark here seems relevant: mathworks tip, specifically the part about "Indexing into an N-D array with N subscripts without knowing N ahead of time (see fftshift for an example)", except a) I'm indexing into an ND array without knowing D, and b) looking at fftshift did not help.
To be completely clear, here's some code illustrating the problem
qq(:,:,1)=[1 2; 3 4];
qq(:,:,2)=[5 6; 7 8];
indx=[1 1 1; 2 2 2] %to reference the coordinates (1,1,1)=1, and (2,2,2)=8
Thanks for looking at my question.
Edit* Sorry about qq missing the '8'.
1 个评论
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!