Mean of columns within matrix blocks of different dimensions
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
fpet
am 1 Apr. 2020
Kommentiert: fpet
am 6 Apr. 2020
I would like to create a matrix M where each column equals to the mean of the matrix blocks of the matrix A.
Case 1: The code below works well when I have subarrays of always 3 columns
B = reshape(A,2151,3,28);
M = squeeze(mean(B,2));
Case 2: But, now I need to group the columns of the matrix A either by 3 or 4.
B = mat2cell(A,2151,[3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 4 3 3 3]);
I created subarrays with mat2cell, but then I don't know how to average each blocks. The squeeze function doesn't work anymore.
Is it possible to produce a similar output than in Case 1 when I have subarrays of different dimensions ?
Thanks in advance for your help
0 Kommentare
Akzeptierte Antwort
Sriram Tadavarty
am 4 Apr. 2020
Hi Fpet,
You can try the following:
B = mat2cell(A,2151,[3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 4 3 3 3]);
bAvgCell = arrayfun(@(x) mean(B{x},2),1:length(B),'UniformOutput',false);
M = cell2mat(bAvgCell);
Hope this helps.
Regards,
Sriram
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!