annotate core/tools/uplot.m @ 0:cc4b1211e677 tip

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