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.
0 个评论
采纳的回答
Sai Sri Harsha Vallabhuni
2020-6-30
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 个评论
madhan ravi
2020-7-1
Nagamani Yaadavalli comments: Mr.Sai, thank you very much for solving my issue. It works.
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!