Effacer les filtres
Effacer les filtres

How to calculate mean of all the rows individually and should be stored in the same worksheet ?

1 vue (au cours des 30 derniers jours)
My worksheet has 271*11 table and it is called 'T'(=filename)
%The variables are %T.Properties.VariableNames = {'Time','L1','L2','L3','L4','L5','L6','L7','L8','L9','L10'}
I woild like to calculate the each column mean by using 'for loop'. I have tried to get the mean value by using
%meanTime = mean(T.Time,'omitnan').
with this formula, I have calculated mean for all columns individually. but the problem is, it is saving in another double file. Doing this, each time is really hectic. With all the output of all(L1','L2','L3','L4','L5','L6','L7','L8','L9','L10') columns except Time, I need to take one average value.
This task I need to repeat for 100s of files. Please explain how to use for loop in this case to find the mean.
Thanksin advance.

Réponse acceptée

Sai Sri Harsha Vallabhuni
Sai Sri Harsha Vallabhuni le 30 Juin 2020
Hey,
I don't know if I understood the question exactly. I'm assuming you want to calculate mean for each column(call them colMean). Then using these, you want to calculate mean for whole file(mean of colMean, call them fileMean). Then mean of all the files.
It can be done if you have way of iteating through filenames as below
sumMeanFile = 0;
for<loop through filenames>
T = readtable(filename);
fileMean = 0;
for idx = 1:size(T, 2)
fileMean = fileMean + mean(table2array(T(:, idx)));
end
sumMeanFile = sumMeanFile + (fileMean/size(T, 2));
end
sumMeanFile = sumMeanFile/noOfFiles;
Hope this answers your question.

Plus de réponses (1)

Steven Lord
Steven Lord le 1 Juil 2020
Use varfun to apply the function @(x) mean(x, 'omitnan') to each variable in the table.

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