How to find out the average of data gathered from a For Loop for a specific column in a table?

1 visualización (últimos 30 días)
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 comentarios
sebastian lim
sebastian lim el 14 de Feb. de 2019
Not 100% sure but i think its a column of just the meanGL values. And its a table.
Got it working now using the code:
meanVal = mean(T.meanGL,1);
This was what i was trying to achieve. Realise i didnt explain it very well.

Iniciar sesión para comentar.

Respuesta aceptada

Peter Perkins
Peter Perkins el 13 de Feb. de 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.
  1 comentario
sebastian lim
sebastian lim el 14 de Feb. de 2019
Thank you very much, i understand the problem. That makes it much clearer! And yes that code is what i am trying to do. Your help is much appreciated.

Iniciar sesión para comentar.

Más respuestas (0)

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!

Translated by