Matrix Manipulation from 4D to 3D

2 次查看(过去 30 天)
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

采纳的回答

the cyclist
the cyclist 2016-12-12
编辑:the cyclist 2016-12-12
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 个评论
Amine Ben Ayara
Amine Ben Ayara 2016-12-12
Mr. Cyclist, You are a life saver! Truly appreciate your help, Happy holidays, Amine

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Calendar 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by