comparison core/tools/uplot.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:e9a9cd732c1e
1 function han = uplot(varargin)
2 % UPLOT Plot of double and FRD data.
3 %
4 % UPLOT([plot_type],SYS1,SYS2,SYS3, ...)
5 % UPLOT([plot_type],[1 10],[.1 5],SYS1, ...)
6 % UPLOT([plot_type],SYS1,'linetype1',SYS2,'linetype2',...)
7 %
8 % Plot double and FRD objects. The syntax is the same as the MATLAB
9 % plot command except that all data is contained in SYSi, and the
10 % axes are specified by PLOT_TYPE.
11 %
12 % The (optional) plot_type argument must be one of:
13 %
14 % 'iv,d' matin .vs. independent variable (default option)
15 % 'iv,m' magnitude .vs. independent variable
16 % 'iv,lm' log(magnitude) .vs. independent variable
17 % 'iv,p' phase .vs. independent variable
18 % 'liv,d' matin .vs. log(independent variable)
19 % 'liv,m' magnitude .vs. log(independent variable)
20 % 'liv,lm' log(magnitude) .vs. log(independent variable)
21 % 'liv,p' phase .vs. log(independent variable)
22 % 'nyq' real .vs. imaginary (parametrized by indep variable)
23 % 'nic' Nichols chart
24 % 'bode' Bode magnitude and phase plots
25 %
26 %See also: BODE, LOGLOG, PLOT, NICHOLS, NYQUIST, SEMILOGX, SEMILOGY, SIGMA.
27
28 % Copyright 2004 The MathWorks, Inc.
29
30 nin = nargin;
31 if isa(varargin{1},'char')
32 plottype = varargin{1};
33 sidx = 2;
34 else
35 plottype = 'iv,d';
36 sidx = 1;
37 end
38
39 argcell = cell(0,1);
40 cnt = 1;
41 cflag = 0;
42 dflag = 0;
43 ydataloc = [];
44 for i=sidx:nin
45 arg = varargin{i};
46 switch class(arg)
47 case 'frd'
48 if dflag==1
49 error('Double data must come in pairs');
50 else
51 cflag = 0;
52 szm = size(arg);
53 if length(szm)==2
54 npts = length(arg.Frequency);
55 ydata = reshape(arg.ResponseData,[szm(1)*szm(2) npts]).';
56 xdata = arg.Frequency;
57 argcell = [argcell;{xdata};{ydata}];
58 ydataloc = [ydataloc;cnt+1];
59 cnt = cnt + 2;
60 else
61 nad = length(szm) - 2;
62 npts = length(arg.Frequency);
63 tmp = permute(arg.ResponseData,[1 2 4:4+nad-1 3]);
64 ydata = reshape(tmp,[prod(szm) npts]).';
65 xdata = arg.Frequency;
66 argcell = [argcell;{xdata};{ydata}];
67 ydataloc = [ydataloc;cnt+1];
68 cnt = cnt + 2;
69 end
70 end
71 case 'char'
72 if dflag==1
73 error('Double data must come in pairs');
74 else
75 if cflag==0
76 argcell = [argcell;{arg}];
77 cnt = cnt + 1;
78 cflag = 1;
79 else
80 error('Never have 2 chars in a row');
81 end
82 end
83 case 'double'
84 cflag = 0;
85 if dflag==0 % think xdata
86 argcell = [argcell;{arg}];
87 cnt = cnt + 1;
88 dflag = 1;
89 elseif dflag==1 % think ydata
90 argcell = [argcell;{arg}];
91 ydataloc = [ydataloc;cnt];
92 cnt = cnt + 1;
93 dflag = 0;
94 end
95 otherwise
96 if isuncertain(arg)
97 error('Cannot plot uncertain matrices or systems');
98 else
99 error('Cannot plot this type of data');
100 end
101 end
102 end
103 xmin = inf;
104 xmax = -inf;
105 for i=1:length(ydataloc)
106 xmin = min([xmin min(argcell{ydataloc(i)-1})]);
107 xmax = max([xmax max(argcell{ydataloc(i)-1})]);
108 end
109 for i=1:length(ydataloc)
110 if length(argcell{ydataloc(i)})==1
111 argcell{ydataloc(i)} = [argcell{ydataloc(i)} argcell{ydataloc(i)}];
112 argcell{ydataloc(i)-1} = [xmin xmax];
113 end
114 end
115
116 switch plottype
117 case 'iv,d'
118 h = plot(argcell{:});
119 case 'iv,m'
120 for i=1:length(ydataloc)
121 argcell{ydataloc(i)} = abs(argcell{ydataloc(i)});
122 end
123 h = plot(argcell{:});
124 case 'iv,lm'
125 for i=1:length(ydataloc)
126 argcell{ydataloc(i)} = abs(argcell{ydataloc(i)});
127 end
128 h = semilogy(argcell{:});
129 case 'iv,p'
130 for i=1:length(ydataloc)
131 argcell{ydataloc(i)} = (180/pi)*angle(argcell{ydataloc(i)});
132 end
133 h = plot(argcell{:});
134 case 'liv,d'
135 h = semilogx(argcell{:});
136 case 'liv,ld'
137 h = loglog(argcell{:});
138 case 'liv,m'
139 for i=1:length(ydataloc)
140 argcell{ydataloc(i)} = abs(argcell{ydataloc(i)});
141 end
142 h = semilogx(argcell{:});
143 case 'liv,lm'
144 for i=1:length(ydataloc)
145 argcell{ydataloc(i)} = abs(argcell{ydataloc(i)});
146 end
147 h = loglog(argcell{:});
148 case 'liv,p'
149 for i=1:length(ydataloc)
150 argcell{ydataloc(i)} = (180/pi)*angle(argcell{ydataloc(i)});
151 end
152 h = semilogx(argcell{:});
153 case {'nyq'}
154 for i=1:length(ydataloc)
155 %x-data, real part
156 argcell{ydataloc(i)-1} = real(argcell{ydataloc(i)});
157 argcell{ydataloc(i)} = imag(argcell{ydataloc(i)});
158 end
159 h = plot(argcell{:});
160 case {'ri'}
161 for i=1:length(ydataloc)
162 %x-data, real part
163 argcell{ydataloc(i)-1} = real(argcell{ydataloc(i)});
164 %y-data, imag part
165 argcell{ydataloc(i)} = imag(argcell{ydataloc(i)});
166 end
167 h = plot(argcell{:});
168 case {'nic'}
169 for i=1:length(ydataloc)
170 %x-data, imag part
171 argcell{ydataloc(i)-1} = 360/(2*pi)*negangle(argcell{ydataloc(i)});
172 %y-data, real part
173 argcell{ydataloc(i)} = 20*log10(abs(argcell{ydataloc(i)}));
174 end
175 h = plot(argcell{:});
176 case 'bode'
177 subplot(2,1,1)
178 magcell = argcell;
179 for i=1:length(ydataloc)
180 magcell{ydataloc(i)} = abs(magcell{ydataloc(i)});
181 end
182 hm = loglog(magcell{:});
183 subplot(2,1,2)
184 for i=1:length(ydataloc)
185 argcell{ydataloc(i)} = (180/pi)*angle(argcell{ydataloc(i)});
186 end
187 hp = semilogx(argcell{:});
188 h = [hm;hp];
189 otherwise
190 error('invalid plot type');
191 end
192
193 if nargout==1
194 han = h;
195 end