简体   繁体   中英

Matlab - computing statistics (max, min, mean, median, std …) at once

I believe that therre is a simple answer but I have not found it. I want to compute statistics for an array (max, min, mean, median, std) in other way than:

max = max(array)
min = min(array)
mean = mean(array)
median = median(array)
std = std(array

because (as I believe) it would go through the array every single time at least once. I am hoping that there is some function like

[max, min, mean, median, std,...] = stat(array)

similar to the R function

summary(Array) #R code

or to the stata command

des //stata

What function should I use in matlab?

Here's a function that does it:

function [maxout, minout, meanout, medianout, stdout] = summary(array)

maxout    = max(array);
minout    = min(array);
meanout   = mean(array);
medianout = median(array);
stdout    = std(array);

Just copy that, save it to a file on your path called summary.m , and you should be good to go.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM