wolffd@0: function han = uplot(varargin) wolffd@0: % UPLOT Plot of double and FRD data. wolffd@0: % wolffd@0: % UPLOT([plot_type],SYS1,SYS2,SYS3, ...) wolffd@0: % UPLOT([plot_type],[1 10],[.1 5],SYS1, ...) wolffd@0: % UPLOT([plot_type],SYS1,'linetype1',SYS2,'linetype2',...) wolffd@0: % wolffd@0: % Plot double and FRD objects. The syntax is the same as the MATLAB wolffd@0: % plot command except that all data is contained in SYSi, and the wolffd@0: % axes are specified by PLOT_TYPE. wolffd@0: % wolffd@0: % The (optional) plot_type argument must be one of: wolffd@0: % wolffd@0: % 'iv,d' matin .vs. independent variable (default option) wolffd@0: % 'iv,m' magnitude .vs. independent variable wolffd@0: % 'iv,lm' log(magnitude) .vs. independent variable wolffd@0: % 'iv,p' phase .vs. independent variable wolffd@0: % 'liv,d' matin .vs. log(independent variable) wolffd@0: % 'liv,m' magnitude .vs. log(independent variable) wolffd@0: % 'liv,lm' log(magnitude) .vs. log(independent variable) wolffd@0: % 'liv,p' phase .vs. log(independent variable) wolffd@0: % 'nyq' real .vs. imaginary (parametrized by indep variable) wolffd@0: % 'nic' Nichols chart wolffd@0: % 'bode' Bode magnitude and phase plots wolffd@0: % wolffd@0: %See also: BODE, LOGLOG, PLOT, NICHOLS, NYQUIST, SEMILOGX, SEMILOGY, SIGMA. wolffd@0: wolffd@0: % Copyright 2004 The MathWorks, Inc. wolffd@0: wolffd@0: nin = nargin; wolffd@0: if isa(varargin{1},'char') wolffd@0: plottype = varargin{1}; wolffd@0: sidx = 2; wolffd@0: else wolffd@0: plottype = 'iv,d'; wolffd@0: sidx = 1; wolffd@0: end wolffd@0: wolffd@0: argcell = cell(0,1); wolffd@0: cnt = 1; wolffd@0: cflag = 0; wolffd@0: dflag = 0; wolffd@0: ydataloc = []; wolffd@0: for i=sidx:nin wolffd@0: arg = varargin{i}; wolffd@0: switch class(arg) wolffd@0: case 'frd' wolffd@0: if dflag==1 wolffd@0: error('Double data must come in pairs'); wolffd@0: else wolffd@0: cflag = 0; wolffd@0: szm = size(arg); wolffd@0: if length(szm)==2 wolffd@0: npts = length(arg.Frequency); wolffd@0: ydata = reshape(arg.ResponseData,[szm(1)*szm(2) npts]).'; wolffd@0: xdata = arg.Frequency; wolffd@0: argcell = [argcell;{xdata};{ydata}]; wolffd@0: ydataloc = [ydataloc;cnt+1]; wolffd@0: cnt = cnt + 2; wolffd@0: else wolffd@0: nad = length(szm) - 2; wolffd@0: npts = length(arg.Frequency); wolffd@0: tmp = permute(arg.ResponseData,[1 2 4:4+nad-1 3]); wolffd@0: ydata = reshape(tmp,[prod(szm) npts]).'; wolffd@0: xdata = arg.Frequency; wolffd@0: argcell = [argcell;{xdata};{ydata}]; wolffd@0: ydataloc = [ydataloc;cnt+1]; wolffd@0: cnt = cnt + 2; wolffd@0: end wolffd@0: end wolffd@0: case 'char' wolffd@0: if dflag==1 wolffd@0: error('Double data must come in pairs'); wolffd@0: else wolffd@0: if cflag==0 wolffd@0: argcell = [argcell;{arg}]; wolffd@0: cnt = cnt + 1; wolffd@0: cflag = 1; wolffd@0: else wolffd@0: error('Never have 2 chars in a row'); wolffd@0: end wolffd@0: end wolffd@0: case 'double' wolffd@0: cflag = 0; wolffd@0: if dflag==0 % think xdata wolffd@0: argcell = [argcell;{arg}]; wolffd@0: cnt = cnt + 1; wolffd@0: dflag = 1; wolffd@0: elseif dflag==1 % think ydata wolffd@0: argcell = [argcell;{arg}]; wolffd@0: ydataloc = [ydataloc;cnt]; wolffd@0: cnt = cnt + 1; wolffd@0: dflag = 0; wolffd@0: end wolffd@0: otherwise wolffd@0: if isuncertain(arg) wolffd@0: error('Cannot plot uncertain matrices or systems'); wolffd@0: else wolffd@0: error('Cannot plot this type of data'); wolffd@0: end wolffd@0: end wolffd@0: end wolffd@0: xmin = inf; wolffd@0: xmax = -inf; wolffd@0: for i=1:length(ydataloc) wolffd@0: xmin = min([xmin min(argcell{ydataloc(i)-1})]); wolffd@0: xmax = max([xmax max(argcell{ydataloc(i)-1})]); wolffd@0: end wolffd@0: for i=1:length(ydataloc) wolffd@0: if length(argcell{ydataloc(i)})==1 wolffd@0: argcell{ydataloc(i)} = [argcell{ydataloc(i)} argcell{ydataloc(i)}]; wolffd@0: argcell{ydataloc(i)-1} = [xmin xmax]; wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: switch plottype wolffd@0: case 'iv,d' wolffd@0: h = plot(argcell{:}); wolffd@0: case 'iv,m' wolffd@0: for i=1:length(ydataloc) wolffd@0: argcell{ydataloc(i)} = abs(argcell{ydataloc(i)}); wolffd@0: end wolffd@0: h = plot(argcell{:}); wolffd@0: case 'iv,lm' wolffd@0: for i=1:length(ydataloc) wolffd@0: argcell{ydataloc(i)} = abs(argcell{ydataloc(i)}); wolffd@0: end wolffd@0: h = semilogy(argcell{:}); wolffd@0: case 'iv,p' wolffd@0: for i=1:length(ydataloc) wolffd@0: argcell{ydataloc(i)} = (180/pi)*angle(argcell{ydataloc(i)}); wolffd@0: end wolffd@0: h = plot(argcell{:}); wolffd@0: case 'liv,d' wolffd@0: h = semilogx(argcell{:}); wolffd@0: case 'liv,ld' wolffd@0: h = loglog(argcell{:}); wolffd@0: case 'liv,m' wolffd@0: for i=1:length(ydataloc) wolffd@0: argcell{ydataloc(i)} = abs(argcell{ydataloc(i)}); wolffd@0: end wolffd@0: h = semilogx(argcell{:}); wolffd@0: case 'liv,lm' wolffd@0: for i=1:length(ydataloc) wolffd@0: argcell{ydataloc(i)} = abs(argcell{ydataloc(i)}); wolffd@0: end wolffd@0: h = loglog(argcell{:}); wolffd@0: case 'liv,p' wolffd@0: for i=1:length(ydataloc) wolffd@0: argcell{ydataloc(i)} = (180/pi)*angle(argcell{ydataloc(i)}); wolffd@0: end wolffd@0: h = semilogx(argcell{:}); wolffd@0: case {'nyq'} wolffd@0: for i=1:length(ydataloc) wolffd@0: %x-data, real part wolffd@0: argcell{ydataloc(i)-1} = real(argcell{ydataloc(i)}); wolffd@0: argcell{ydataloc(i)} = imag(argcell{ydataloc(i)}); wolffd@0: end wolffd@0: h = plot(argcell{:}); wolffd@0: case {'ri'} wolffd@0: for i=1:length(ydataloc) wolffd@0: %x-data, real part wolffd@0: argcell{ydataloc(i)-1} = real(argcell{ydataloc(i)}); wolffd@0: %y-data, imag part wolffd@0: argcell{ydataloc(i)} = imag(argcell{ydataloc(i)}); wolffd@0: end wolffd@0: h = plot(argcell{:}); wolffd@0: case {'nic'} wolffd@0: for i=1:length(ydataloc) wolffd@0: %x-data, imag part wolffd@0: argcell{ydataloc(i)-1} = 360/(2*pi)*negangle(argcell{ydataloc(i)}); wolffd@0: %y-data, real part wolffd@0: argcell{ydataloc(i)} = 20*log10(abs(argcell{ydataloc(i)})); wolffd@0: end wolffd@0: h = plot(argcell{:}); wolffd@0: case 'bode' wolffd@0: subplot(2,1,1) wolffd@0: magcell = argcell; wolffd@0: for i=1:length(ydataloc) wolffd@0: magcell{ydataloc(i)} = abs(magcell{ydataloc(i)}); wolffd@0: end wolffd@0: hm = loglog(magcell{:}); wolffd@0: subplot(2,1,2) wolffd@0: for i=1:length(ydataloc) wolffd@0: argcell{ydataloc(i)} = (180/pi)*angle(argcell{ydataloc(i)}); wolffd@0: end wolffd@0: hp = semilogx(argcell{:}); wolffd@0: h = [hm;hp]; wolffd@0: otherwise wolffd@0: error('invalid plot type'); wolffd@0: end wolffd@0: wolffd@0: if nargout==1 wolffd@0: han = h; wolffd@0: end