LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
stat.m
1function [ ] = stat(variable)
2%STAT prints some quick statistics about a variable in the command window.
3%
4%% Syntax and description
5%
6% stat(variable) prints the following properties of a variable in the
7% command window:
8%
9% size: size of variable.
10% numel: number of elements in variable.
11% NaNs: number of not-a-number values in variable.
12% maximum: maximum value in variable across all dimensions.
13% minimum: minimum value in variable across all dimensions.
14% mean: mean value of variable across all dimensions.
15% median: median value of variable across all dimensions.
16% mode: most frequent value in variable across all dimensions.
17% std dev: standard deviation of variable across all dimensions.
18% variance: variance of variable across all dimensions.
19%
20%% Examples
21%
22% A = magic(5)
23% A =
24% 17 24 1 8 15
25% 23 5 7 14 16
26% 4 6 13 20 22
27% 10 12 19 21 3
28% 11 18 25 2 9
29%
30% stat(A)
31%
32% Properties of A:
33% size = 5 5
34% numel = 25
35% NaNs = 0
36% maximum = 25
37% minimum = 1
38% mean = 13
39% median = 13
40% mode = 1
41% std dev = 7.3598
42% variance = 54.1667
43%
44%
45% % Also works with NaNs:
46%
47% A(2:4)=NaN
48% A =
49% 17 24 1 8 15
50% NaN 5 7 14 16
51% NaN 6 13 20 22
52% NaN 12 19 21 3
53% 11 18 25 2 9
54%
55% stat(A)
56%
57% Properties of A:
58% size = 5 5
59% numel = 25
60% NaNs = 3
61% maximum = 25
62% minimum = 1
63% mean = 13.0909
64% median = 13.5
65% mode = 1
66% std dev = 7.2697
67% variance = 52.8485
68%
69%% Author Info
70% This function was written by Chad A. Greene (www.chadagreene.com) of the
71% University of Texas Institute for Geophysics, October 2014.
72%
73% See also: who, whos, mean, median, mode, size, numel.
74
75assert(nargin==1,'stat function requires exactly one input variable.')
76
77disp(' ')
78disp([' Properties of ',inputname(1),':'])
79disp([' size = ',num2str(size(variable))])
80disp([' numel = ',num2str(numel(variable))])
81disp([' NaNs = ',num2str(sum(isnan(variable(:))))])
82
83disp([' maximum = ',num2str(max(variable(isfinite(variable))))])
84disp([' minimum = ',num2str(min(variable(isfinite(variable))))])
85disp([' mean = ',num2str(mean(variable(isfinite(variable))))])
86disp([' median = ',num2str(median(variable(isfinite(variable))))])
87disp([' mode = ',num2str(mode(variable(isfinite(variable))))])
88disp([' std dev = ',num2str(std(variable(isfinite(variable))))])
89disp([' variance = ',num2str(var(variable(isfinite(variable))))])
90disp(' ')
91
92
93
94end
95