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