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

1 次查看(过去 30 天)
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.

采纳的回答

Sai Sri Harsha Vallabhuni
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.

更多回答(1 个)

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

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by