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