How to calculate mean of all the rows individually and should be stored in the same worksheet ?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Nagamani Yaadavalli
el 29 de Jun. de 2020
Respondida: Steven Lord
el 1 de Jul. de 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 comentarios
Respuesta aceptada
Sai Sri Harsha Vallabhuni
el 30 de Jun. de 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 comentario
madhan ravi
el 1 de Jul. de 2020
Nagamani Yaadavalli comments: Mr.Sai, thank you very much for solving my issue. It works.
Más respuestas (1)
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!