Hello,
I havea cell A (107x3), with each 14x8 double.
I want to create a cell A_mean 1x3 that just contain three 14x8 doubles, that are the mean of all the value.
I mean, A_mean{1,1}(1,1) should be the mean(A{1,1}(1,1),A{2,1}(1,1)...A{107,1}(1,1)), and the same for all the others numbers.
I really don't know how can I do it..
Thanks in advance :)

 Réponse acceptée

% a cell A (107x3), with each 14x8 double
A = arrayfun(@(~)randn(14,8),zeros(107,3),'UniformOutput',false)
A = 107×3 cell array
{14×8 double} {14×8 double} {14×8 double} {14×8 double} {14×8 double} {14×8 double} {14×8 double} {14×8 double} {14×8 double} {14×8 double} {14×8 double} {14×8 double} {14×8 double} {14×8 double} {14×8 double} {14×8 double} {14×8 double} {14×8 double} {14×8 double} {14×8 double} {14×8 double} {14×8 double} {14×8 double} {14×8 double} {14×8 double} {14×8 double} {14×8 double} {14×8 double} {14×8 double} {14×8 double} {14×8 double} {14×8 double} {14×8 double} {14×8 double} {14×8 double} {14×8 double} {14×8 double} {14×8 double} {14×8 double} {14×8 double} {14×8 double} {14×8 double} {14×8 double} {14×8 double} {14×8 double} {14×8 double} {14×8 double} {14×8 double}
% I want to create a cell A_mean 1x3 that just contain three
% 14x8 doubles, that are the mean of all the value
N = size(A,2);
A_mean = cell(1,N);
for ii = 1:N
A_mean{ii} = mean(cat(3,A{:,ii}),3);
end
disp(A_mean);
{14×8 double} {14×8 double} {14×8 double}

4 commentaires

Fabio Taccaliti
Fabio Taccaliti le 8 Juil 2022
Modifié(e) : Fabio Taccaliti le 8 Juil 2022
Thanks a lot Voss! This it is what I was looking for!
If I would like to do the average of only just the last 50 doubles of the cell A, I have to do
N = size(A,2);
A_mean = cell(1,N);
for ii = 1:N
A_mean{ii} = mean(cat(3,A{length(A)-50:length(A),ii}),3);
end
disp(A_mean);
Right?
Voss
Voss le 8 Juil 2022
That will be the average of the last 51 (!) 14x8 matrices in each column of A, but yeah.
Using end is better than using length(A), so do A{end-49:end,ii} to get the last 50.
Fabio Taccaliti
Fabio Taccaliti le 8 Juil 2022
Ohh you are right!! Thanks a lot for the help!
Voss
Voss le 8 Juil 2022
You're welcome!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Produits

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by