Reduce Matrix Dimensions for 5D-Data

4 vues (au cours des 30 derniers jours)
Matthias Saurer
Matthias Saurer le 27 Jan 2021
Commenté : Matthias Saurer le 31 Jan 2021
Lets say we have a 5D-Matrix M and want to convert it to 4D-matrix M' in a way such that we combine dim1 and dim3 into a new dim1':
Or more mathematically (hopefully this notation is understandable):
M'(:,m,n,p) = M(:,m,:,n,p) for all m,n,p.
Obviously we could use loops for that, but im looking for a more elegant way, maybe we could make clever use of sub2ind?
  2 commentaires
Mara
Mara le 27 Jan 2021
Hey Matthias,
maybe the function reshape() might help you with that
Matthias Saurer
Matthias Saurer le 31 Jan 2021
You were absoluteley rigth, and permute was the last piece of the puzzle. Thanks for your help, Mara

Connectez-vous pour commenter.

Réponse acceptée

Srivardhan Gadila
Srivardhan Gadila le 30 Jan 2021
You can make use of the functions permute and reshape as follows:
% M is a matrix of size a x b x c x d x e
Mp = permute(M,[1 3 2 4 5]);
Md = reshape(Mp,[],b,d,e);
  1 commentaire
Matthias Saurer
Matthias Saurer le 31 Jan 2021
Nice and simple, thank you Sir!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB 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