Subset multidimensional array using a vector

4 vues (au cours des 30 derniers jours)
Francisco Garrido
Francisco Garrido le 10 Sep 2019
Modifié(e) : Matt J le 10 Sep 2019
I have an array A of 7 dimensions, and a vector v of length 5.
I need to select a subset of A where the first five coordinates are the ones specified by V. I can accomplish this by:
A(v(1), v(2), v(3), v(4), v(5), :, :)
but it wont work if the length of v changes from one application to another. Is there any way straight forward way to go about this?
Thanks!!!

Réponses (1)

Matt J
Matt J le 10 Sep 2019
Modifié(e) : Matt J le 10 Sep 2019
idx=repmat({':'},1,ndims(A));
idx(1:numel(v))=num2cell(v);
result=A(idx{:});

Catégories

En savoir plus sur Structures dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by