How to find out the average of data gathered from a For Loop for a specific column in a table?
1 view (last 30 days)
Show older comments
sebastian lim
on 13 Feb 2019
Commented: sebastian lim
on 14 Feb 2019
The script is finding out the mean pixel intensities in a ROI as well as other properties of sequential images in the folder.
I am trying to find out how to find the average of a certain column (meanGL) in the table T that is created from data gathered in the For Loop, this part of the code is not working. I am trying to find the average of the meanGL values.
% Creates table from For Loop Values with separate column for each variable
T.Properties.VariableNames={'numberOfPixels1' 'numberOfPixels2 ' 'meanGL'};
%Calculate the average meanGL for those specific layers
B = T(:,[3])
meanVal = mean(B,1)
% Name the file
filename='Thermal Imaging Data.xlsx'
% Write the data into named excel spreadsheet
writetable(T,filename,'Sheet',1,'Range','B2')
The whole script I am using is attatched.
Also if this average could also be displayed in the same excel spreadsheet as the rest of the data that would be wonderful?
4 Comments
Accepted Answer
Peter Perkins
on 13 Feb 2019
The problem is that you are passing a table into mean. The table is a container, and what you need to do is to pass the variable in the table to mean. A one-variable table is not the same thing as the one variable.
You have variable names, you should use them!
meanVal = mean(T.meanGL,1);
There's more than one mean going on there, I guess, but I think that does what you are trying to do.
More Answers (0)
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!