MATLAB: How to calculate the mean/median/Standard deviation for each column in a table

table/columns/mean/median/standard deviation

Here I have table has 716rows*9 coloumns called Analysis1 as shown in figure1.
I would like to each the following steps:
  1. The calcualtions for n number of files like this in a folder
  2. The formula should be calculated for each coulmn (not for rows) and all the values shoul be store in a one seperate file so that I can plot a graph
I have tried the formula using median(Analysis1) but showing the permute error as shown in figure 2.
I have suceeded applying the formula for an individual coulumn like as shown in figure2:
  1. Result1 = median(Analysis.Time)
  2. Result2 = median(Analysis.TempL1)
Any suggestion would be appreciated to solve this issue. Thanks in advance.

Best Answer

Let's look at a sample table.
load patients
T = table(LastName, Smoker, Height, Weight, Systolic, Diastolic);
head(T)
ans = 8x6 table
LastName Smoker Height Weight Systolic Diastolic ____________ ______ ______ ______ ________ _________ {'Smith' } true 71 176 124 93 {'Johnson' } false 69 163 109 77 {'Williams'} false 64 131 125 83 {'Jones' } false 67 133 117 75 {'Brown' } false 64 119 122 80 {'Davis' } false 68 142 121 70 {'Miller' } true 64 142 130 88 {'Wilson' } false 68 180 115 82
It makes sense to compute the mean for four variables in this table, but not for the LastName or Smoker variables.
M = varfun(@mean, T, 'InputVariables', @isnumeric)
M = 1x4 table
mean_Height mean_Weight mean_Systolic mean_Diastolic ___________ ___________ _____________ ______________ 67.07 154 122.78 82.96
This looks for all the variables in T for which isnumeric returns true and calls mean on those variables.