How can i create a descriptive statistics table for columns
    14 次查看(过去 30 天)
  
       显示 更早的评论
    
Hey Guys!
My MatLab skills are pretty pretty basic and now i need your help with something, because i can't find the answer here. So i have a 15x10 data.mat where there are 10 variables with 15 values. Now i want some descreptive statistics of those variables.
The perfect solution would be a group that looks kind of like this:
            Mean  Max  Std  ...
Variable 1   x     x    x
Variable 2   x     x    x 
...
Is there any way to achieve a table/group like this?
Thank you very much in advance!
0 个评论
采纳的回答
  David Fletcher
      
 2018-4-7
        The default behavior for most of the statistical function is for column-wise operation and since that is what you want you can just apply them to your data matrix. So, if you want to collate the results together in a matrix:
results=[mean(data)' max(data)' std(data)']
If you specically want a table then:
dummyData=randi(10,15,10)
results=table()
results.Mean=mean(dummyData)'
results.Max=max(dummyData)'
results.Std_dev=std(dummyData)'
results =
10×3 table
     Mean     Max    Std_dev
    ______    ___    _______
       5.6    10     3.4184 
    5.0667     9     2.7894 
    4.6667    10     3.2878 
    6.0667    10     2.7894 
       5.2    10     2.8082 
    5.0667    10     2.5765 
         5    10     2.9032 
       5.6    10     2.7464 
    5.5333    10     2.8502 
       5.2     9     2.5967
更多回答(2 个)
  Peter Perkins
    
 2018-4-11
        Another possibility:
>> t = array2table(rand(10,5))
t =
  10×5 table
      Var1        Var2       Var3        Var4        Var5   
    ________    ________    _______    ________    _________
     0.69989     0.96865    0.28101     0.67612      0.78052
     0.63853     0.53133    0.44009     0.28906      0.67533
    0.033604     0.32515    0.52714     0.67181    0.0067153
    0.068806     0.10563    0.45742     0.69514      0.60217
      0.3196     0.61096    0.87537    0.067993      0.38677
     0.53086      0.7788    0.51805     0.25479      0.91599
     0.65445     0.42345    0.94362     0.22404    0.0011511
     0.40762    0.090823    0.63771     0.66783      0.46245
     0.81998     0.26647    0.95769     0.84439      0.42435
     0.71836     0.15366    0.24071     0.34446      0.46092
>> t2 = varfun(@(x) [mean(x); max(x); std(x)],t)
t2 =
  3×5 table
    Fun_Var1    Fun_Var2    Fun_Var3    Fun_Var4    Fun_Var5
    ________    ________    ________    ________    ________
    0.48917     0.42549     0.58788     0.47356     0.47164 
    0.81998     0.96865     0.95769     0.84439     0.91599 
    0.27434     0.29609     0.26046     0.26458     0.29787 
>> t2.Properties.RowNames = {'mean' 'max' 'std'}
t2 =
  3×5 table
            Fun_Var1    Fun_Var2    Fun_Var3    Fun_Var4    Fun_Var5
            ________    ________    ________    ________    ________
    mean    0.48917     0.42549     0.58788     0.47356     0.47164 
    max     0.81998     0.96865     0.95769     0.84439     0.91599 
    std     0.27434     0.29609     0.26046     0.26458     0.29787 
>> t2.Properties.VariableNames = extractAfter(t2.Properties.VariableNames,'Fun_')
t2 =
  3×5 table
             Var1       Var2       Var3       Var4       Var5  
            _______    _______    _______    _______    _______
    mean    0.48917    0.42549    0.58788    0.47356    0.47164
    max     0.81998    0.96865    0.95769    0.84439    0.91599
    std     0.27434    0.29609    0.26046    0.26458    0.29787
That's the wrong orientation for what you asked. In R2018a, you could use rows2vars to "flip" it the other way 'round.
0 个评论
  Jennifer Rebbin
    
 2025-7-10
        
      移动:Stephen23
      
      
 2025-7-11
  
      Starting in R2024b, you can use the summary function and specify the statistics to compute using the Statistics name-value argument.
A = rand(15,10);
summary(A,Statistics=["mean" "max" "std"])
0 个评论
另请参阅
类别
				在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



