Effacer les filtres
Effacer les filtres

Matrix Manipulation from 4D to 3D

2 vues (au cours des 30 derniers jours)
Amine Ben Ayara
Amine Ben Ayara le 12 Déc 2016
Commenté : Amine Ben Ayara le 12 Déc 2016
Good morning Matlab Community, I hope all of you are doing well. I need some help with manipulating matrix dimensions. I have 4D matrix of the following dimension (5*5 by14680 by50), so in my own simple words, I have 50 sets of 14680 (5*5) matrices. What I would like to do is do the following operation for each matrix: Suppose for a given 5*5 matrix; get sum of 1st column, then the sum of the first row, then compute the difference (Sum of the 1st column minus sum of 1st row) [ Difference=(sum(:,1)-sum(1,:))] Next is basically manipulating the output: Final matrix should be of dimension (14680*50) (each row element contains a value for the difference calculate above) So this matrix is now 2D and I can just plot a curve for each row (change of the difference calculated from 1 to 50) I would greatly appreciate any guidance, Thank you so much, Amine

Réponse acceptée

the cyclist
the cyclist le 12 Déc 2016
Modifié(e) : the cyclist le 12 Déc 2016
I think this does what you describe ...
% Some made-up data
M = rand(5,5,14680,50);
sumCol1 = squeeze(sum(M(:,1,:,:),1));
sumRow1 = squeeze(sum(M(1,:,:,:),2));
diffColRow = sumCol1 - sumRow1;
Also, you don't really need the intermediate variables:
diffColRow = squeeze(sum(M(:,1,:,:),1)) - squeeze(sum(M(1,:,:,:),2));
  1 commentaire
Amine Ben Ayara
Amine Ben Ayara le 12 Déc 2016
Mr. Cyclist, You are a life saver! Truly appreciate your help, Happy holidays, Amine

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

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