How to find a vector containing mean values of the corresponding cells?

2 vues (au cours des 30 derniers jours)
Shehr Bano Fatima
Shehr Bano Fatima le 14 Déc 2020
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 commentaire
Ive J
Ive J le 19 Déc 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.

Connectez-vous pour commenter.

Réponses (2)

Matt J
Matt J le 19 Déc 2020
Modifié(e) : Matt J le 19 Déc 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
Name Size Bytes Class Attributes A 1197000x6 57456000 double Ameans 9000x1 72000 double

Srivardhan Gadila
Srivardhan Gadila le 20 Déc 2020
You can refer to the documentation of for, mean and write the code.
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);
You can refer to the documentation of mean & cellfun and make changes to the above code to fit with your problem exactly.

Catégories

En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by