-
Notifications
You must be signed in to change notification settings - Fork 0
/
datastats.m
executable file
·75 lines (67 loc) · 2.09 KB
/
datastats.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
function [xds,yds] = datastats(xdata, ydata)
%DATASTATS Data statistics.
% DS = DATASTATS(XDATA) returns data statistics for XDATA in the
% structure DS. XDATA should be a real column vector and the
% imaginary part of complex XDATA is ignored.
%
% The returned structure DS contains the following fields:
%
% ds.num --- number of points in the data
% ds.max --- maximum of the data
% ds.min --- minimum of the data
% ds.mean --- mean of the data
% ds.median --- median of the data
% ds.range --- difference between max and min
% ds.std --- standard deviation of the data
%
% [XDS,YDS] = DATASTATS(XDATA,YDATA) returns data statistics for
% XDATA and YDATA in the structures XDS and YDS. XDATA and YDATA
% should be real column vectors and the imaginary parts of complex
% inputs are ignored. XDS and YDS are structures as in the above
% case.
% Copyright 1999-2004 The MathWorks, Inc.
% $Revision: 1.12.2.3 $ $Date: 2005/03/07 17:26:37 $
if nargin < 1
error('curvefit:datastats:noInput', ...
'DATASTATS require at least one input argument.');
end
if size(xdata,2) ~= 1
xdata = xdata';
% error('curvefit:datastats:xDataMustBeColVector', ...
% 'Xdata must be a column vector.');
end
cplxflag = 0;
if ~isreal(xdata)
cplxflag = 1;
xdata = real(xdata);
end
if nargin >= 2
if size(ydata,2) ~= 1
error('curvefit:datastats:yDataMustBeColVector', ...
'Ydata must be a column vector.');
end
if ~isreal(ydata)
cplxflag = 1;
ydata = real(ydata);
end
end
if cplxflag
warning('curvefit:datastats:usingRealComp', ...
'Using only the real component of complex data.');
end
xds.num = length(xdata);
xds.max = max(xdata);
xds.min = min(xdata);
xds.mean = mean(xdata);
xds.median = median(xdata);
xds.range = xds.max-xds.min;
xds.std = std(xdata);
if nargout == 2 && nargin == 2
yds.num = length(ydata);
yds.max = max(ydata);
yds.min = min(ydata);
yds.mean = mean(ydata);
yds.median = median(ydata);
yds.range = yds.max-yds.min;
yds.std = std(ydata);
end