Mean of columns within matrix blocks of different dimensions

3 visualizaciones (últimos 30 días)
fpet
fpet el 1 de Abr. de 2020
Comentada: fpet el 6 de Abr. de 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

Respuesta aceptada

Sriram Tadavarty
Sriram Tadavarty el 4 de Abr. de 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

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by