Mean of columns within matrix blocks of different dimensions

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

采纳的回答

Sriram Tadavarty
Sriram Tadavarty 2020-4-4
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by