How to find a vector containing mean values of the corresponding cells?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
Ive J
2020-12-19
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.
回答(2 个)
Matt J
2020-12-19
编辑:Matt J
2020-12-19
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 个评论
Srivardhan Gadila
2020-12-20
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 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!