How to calculate mean of all the rows individually and should be stored in the same worksheet ?
1 view (last 30 days)
Show older comments
Nagamani Yaadavalli
on 29 Jun 2020
Answered: Steven Lord
on 1 Jul 2020
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.
0 Comments
Accepted Answer
Sai Sri Harsha Vallabhuni
on 30 Jun 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.
1 Comment
madhan ravi
on 1 Jul 2020
Nagamani Yaadavalli comments: Mr.Sai, thank you very much for solving my issue. It works.
More Answers (1)
See Also
Categories
Find more on Logical 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!