How to find a vector containing mean values of the corresponding cells?
1 view (last 30 days)
Show older comments
I have a 133X7 matrix (lets call it A) where each cell of the first 6 columns is a 9000X1 array (let's call it B). I wanna generate a mean vector of the first column of A, such that it contains mean values of all the corresponsing cells inside B. For example, the mean of the first cell values of all Bs should be the first cell value in the resultant vector, the mean of the second cell values of all Bs should be the second cell value in resultant vector and so on.
Does someone know how to do this?
1 Comment
Ive J
on 19 Dec 2020
You question is not clear. Please provide more detailed information (e.g. your script and sample/simulated/real data) so that everybody can understand what you've done and trying to do.
Answers (2)
Matt J
on 19 Dec 2020
Edited: Matt J
on 19 Dec 2020
It's not clear from your description what data type A is, in particular whether it is numeric or a cell array,. It shouldn't be a cell array if all cells are 9000x1 arrays. There's never usually a good reason to use a cell array if the cell contents are all the same size. I will assume instead that A is a (133*9000)x6 numeric matrix.
A=rand(133*9000,6);
Ameans=mean(reshape(A,9000,[]),2);
whos A Ameans
0 Comments
Srivardhan Gadila
on 20 Dec 2020
Seems that the question is not completely clear and based on the provided information, the following code may help you:
A = cell(4,2); % 4x2 cell array instead of 133x7
% 9x1 array for B instead of 9000x1
A{1,1} = rand(9,1);
A{2,1} = rand(9,1);
A{3,1} = rand(9,1);
A{4,1} = rand(9,1);
% meanFirstColumn = cellfun(@(x) mean(x),A(:,1),'UniformOutput',true);
meanFirstColumn = cellfun(@(x) mean(x),A(:,1),'UniformOutput',false);
0 Comments
See Also
Categories
Find more on Get Started with MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!