Home > classes > @ao > iplot.m

iplot

PURPOSE ^

PLOT plots an array of analysis objects.

SYNOPSIS ^

function varargout = iplot(varargin)

DESCRIPTION ^

 PLOT plots an array of analysis objects.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 DESCRIPTION: PLOT plots an array of analysis objects.

 CALL:

 PARAMETERS:  complex_view   're/im'   'mag/deg'
              title
              enbw
              legend_names

 VERSION:     $Id: iplot.m,v 1.5 2007/08/24 16:55:29 ingo Exp $

 The following call returns a parameter list object that contains the
 default parameter values:

 >> pl = plot(ao, 'Params')

 HISTORY: 21-08-2007 Diepholz
             Creation

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function varargout = iplot(varargin)
0002 % PLOT plots an array of analysis objects.
0003 %
0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0005 %
0006 % DESCRIPTION: PLOT plots an array of analysis objects.
0007 %
0008 % CALL:
0009 %
0010 % PARAMETERS:  complex_view   're/im'   'mag/deg'
0011 %              title
0012 %              enbw
0013 %              legend_names
0014 %
0015 % VERSION:     $Id: iplot.m,v 1.5 2007/08/24 16:55:29 ingo Exp $
0016 %
0017 % The following call returns a parameter list object that contains the
0018 % default parameter values:
0019 %
0020 % >> pl = plot(ao, 'Params')
0021 %
0022 % HISTORY: 21-08-2007 Diepholz
0023 %             Creation
0024 %
0025 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0026 
0027   %%%%%%%%%%   Check if this is a call for parameters   %%%%%%%%%%
0028   if nargin == 2
0029     if isa(varargin{1}, 'ao') && ischar(varargin{2})
0030       in = char(varargin{1});
0031       if strcmp(in, 'Params')
0032         varargout{1} = getDefaultPL();
0033         return
0034       end
0035     end
0036   end
0037 
0038   axes_handle   = [];
0039   ao_s          = [];
0040   pl_s          = [];
0041   line_spec     = [];
0042   prop_val      = {};
0043 
0044   %%%%%%%%%%   Check input values   %%%%%%%%%%
0045   for ii = 1:nargin
0046     if ishandle(varargin{ii}) & isempty(axes_handle)
0047       axes_handle = varargin{ii};
0048     elseif isa(varargin{ii}, 'ao')
0049       varargin{ii} = reshape(varargin{ii}, 1, []);
0050       ao_s = [ao_s varargin{ii}];
0051     elseif isa(varargin{ii}, 'plist')
0052       pl_s = [pl_s varargin{ii}];
0053     elseif ischar(varargin{ii}) && islinespec(varargin{ii}) && isempty(line_spec)
0054       line_spec = varargin{ii};
0055     else
0056       prop_val = [prop_val, varargin{ii}];
0057     end
0058   end
0059 
0060   pl_s = combine(pl_s, getDefaultPL());
0061 
0062 
0063   %%%%%%%%%%  Get default values from the application-defined data.   %%%%%%%%%%
0064 
0065   len_legend  = getappdata(0, 'wraplegendstringat');
0066 
0067   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0068   %%           Check some display propeties.           %%
0069   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0070   sort_ao = [];
0071   T0_off  = 1e20;
0072 
0073   for ii = 1:length(ao_s)
0074 
0075     [x,y] = get_xy_axis(ao_s(ii).data);
0076 
0077     %%%%%% Get the class name
0078     class_name = class(ao_s(ii).data);
0079 
0080     % If the class_name doesn't exist in the variable sort_ao then add this name
0081     % as a struct.
0082     if isempty(sort_ao) || ~ismember(class_name, fieldnames(sort_ao))
0083       sort_ao.(class_name) = [];
0084     end
0085 
0086     %%%%%   Define the necessary fields (default values)   %%%%%
0087     if isempty(sort_ao.(class_name))
0088       sort_ao.(class_name) = struct('ao',            [],      ...
0089                                     'complex',       false,   ...
0090                                     'complex_view', '',       ...                                    'title_str',    '',       ...
0091                                     'legend_names', '',       ...
0092                                     'xlabel_des',   '',       ...
0093                                     'ylabel_des',   '',       ...
0094                                     'xscale',       'linear', ...
0095                                     'yscale',       'linear');
0096     end
0097 
0098     %%%%%   Set the fields for the associated data   %%%%%
0099     sort_ao.(class_name).ao = [sort_ao.(class_name).ao ao_s(ii)];
0100     sort_ao.(class_name).complex_view = find(pl_s, 'complex_view');
0101     sort_ao.(class_name).title_str    = find(pl_s, 'title_str');
0102     sort_ao.(class_name).legend_names = find(pl_s, 'legend_names');
0103     sort_ao.(class_name).xlabel_des   = find(pl_s, 'xlabel_des');
0104     sort_ao.(class_name).ylabel_des   = find(pl_s, 'ylabel_des');
0105 
0106     if ~isreal(y)
0107       sort_ao.(class_name).complex = true;
0108     end
0109     if (max(x)-min(x)) / 10^floor(log10(mean(abs(x)))) > 9
0110       sort_ao.(class_name).xscale = 'log';
0111     end
0112     if min(x) < 0
0113       sort_ao.(class_name).xscale = 'linear';
0114     end
0115     if (max(y)-min(y)) / 10^floor(log10(mean(abs(y)))) > 9
0116       sort_ao.(class_name).yscale = 'log';
0117     end
0118     if min(y) < 0
0119       sort_ao.(class_name).yscale = 'linear';
0120     end
0121 
0122 
0123     %%%%%%%%%%   Spezial fields for the different data objects   %%%%%%%%%%
0124 
0125     %%%%%   FSDATA   %%%%%
0126     if strcmp(class_name, 'fsdata')
0127       if length (ao_s(ii).data.enbw) > 1
0128         sort_ao.(class_name).enbw = find(pl_s, 'enbw');
0129       end
0130     end
0131 
0132     %%%%%   TSDATA   %%%%%
0133     if strcmp(class_name, 'tsdata')
0134 
0135       t0 = ao_s(ii).data.t0.utc_epoch_milli/1000;
0136       if t0 < T0_off
0137         T0_off = t0;
0138         sort_ao.(class_name).T0_off = t0;
0139       end
0140     end
0141 
0142   end
0143 
0144   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0145   %%           Plot the different data objects           %%
0146   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0147   fields = fieldnames(sort_ao);
0148 
0149   out_line_h   = [];
0150   out_axes_h   = [];
0151   out_figure_h = [];
0152 
0153   for ii = 1:length(fields)
0154     class_name = fields{ii};
0155 
0156     %%%%%%%%%%   Add the t0 offset to all aos with tsdata objects.   %%%%%%%%%%
0157     if strcmp(class_name, 'tsdata')
0158       for jj = 1:length(sort_ao.(class_name).ao)
0159         curr_ao = sort_ao.(class_name).ao(jj);
0160 
0161         t0 = curr_ao.data.t0.utc_epoch_milli/1000;
0162         curr_ao.data.t = curr_ao.data.t + t0 - sort_ao.(class_name).T0_off;
0163 
0164         sort_ao.(class_name).ao(jj) = curr_ao;
0165       end
0166     end
0167 
0168     %%%%%%%%%%   Set default values   %%%%%%%%%%
0169     % Set default title
0170     if isempty (sort_ao.(class_name).title_str)
0171       if sort_ao.(class_name).complex == true
0172         add_text = 'complex ';
0173       else
0174         add_text = '';
0175       end
0176       switch (class_name)
0177         case 'fsdata'
0178           sort_ao.(class_name).title_str = sprintf('Plot of %sfrequency series AOs', add_text);
0179         case 'tsdata'
0180           sort_ao.(class_name).title_str = sprintf('Plot of %stime series AOs', add_text);
0181         case 'cdata'
0182           sort_ao.(class_name).title_str = sprintf('Plot of %sconstant data AOs', add_text);
0183         case 'xydata'
0184           sort_ao.(class_name).title_str = sprintf('Plot of %sxy data AOs', add_text);
0185         otherwise
0186           error('### Unknown data object ''%s''', class_name);
0187       end
0188     end
0189 
0190     % Set default x-, y-units
0191     if isempty(sort_ao.(class_name).ao(1).data.xunits)
0192       xunits = 'unknown';
0193     else
0194       xunits= sort_ao.(class_name).ao(1).data.xunits;
0195     end
0196     if isempty(sort_ao.(class_name).ao(1).data.yunits)
0197       yunits = 'unknown';
0198     else
0199       yunits= sort_ao.(class_name).ao(1).data.yunits;
0200     end
0201 
0202     fig_h = figure;
0203 
0204     %%%%%%%%%%   Plot complex values   %%%%%%%%%%
0205     if sort_ao.(class_name).complex == true
0206 
0207       if strcmp(sort_ao.(class_name).complex_view, 're/im')
0208         axes_h1 = subplot(2,1,1);
0209         line_h1 = plot(axes_h1, real(sort_ao.(class_name).ao), line_spec, prop_val);
0210         axes_h2 = subplot(2,1,2);
0211         line_h2 = plot(axes_h2, imag(sort_ao.(class_name).ao), line_spec, prop_val);
0212 
0213         label_x1 = [sort_ao.(class_name).xlabel_des ' [' xunits ']'];
0214         label_y1 = [sort_ao.(class_name).ylabel_des 'Real [' yunits ']'];
0215         label_y2 = [sort_ao.(class_name).ylabel_des 'Imaginary [' yunits ']'];
0216 
0217         % Do not set the xscale if it is set as a propertie/value pair
0218         if ~ismember('xscale', lower(prop_val))
0219           % If the 'key' exist in the parameter list then do NOT replace the
0220           % value. (see combine) If the user use a different syntax (he use
0221           % upper case letters) this value is put before the user value.
0222           % This function take ALWAYS the user value.
0223           pl_s = combine(pl_s, plist('xscale', sort_ao.(class_name).xscale));
0224         end
0225 
0226         % Plot both y-axes as a linear scale
0227         pl_s = set(pl_s, 'Yscale', 'linear');
0228 
0229       else % if strcmp(sort_ao.(class_name).complex_view, 'mag/deg')
0230         axes_h1 = subplot(3,1,1:2);
0231         line_h1 = plot(axes_h1, abs(sort_ao.(class_name).ao), line_spec, prop_val);
0232         axes_h2 = subplot(3,1,3);
0233         line_h2 = plot(axes_h2, phase(sort_ao.(class_name).ao), line_spec, prop_val);
0234 
0235         label_x1 = [sort_ao.(class_name).xlabel_des ' [' xunits ']'];
0236         label_y1 = [sort_ao.(class_name).ylabel_des 'Magnitude [' yunits ']'];
0237         label_y2 = [sort_ao.(class_name).ylabel_des 'Phase [' yunits ']'];
0238 
0239         % Do not set the xscale if it is set as a propertie/value pair
0240         if ~ismember('xscale', lower(prop_val))
0241           % If the 'key' exist in the parameter list then do NOT replace the
0242           % value. (see combine) If the user use a different syntax (he use
0243           % upper case letters) this value is put before the user value.
0244           % This function take ALWAYS the user value.
0245           pl_s = combine(pl_s, plist('xscale', sort_ao.(class_name).xscale));
0246         end
0247 
0248         % Do not set the yscale if it is set as a propertie/value pair
0249         if ~ismember('yscale', lower(prop_val))
0250           % If the 'key' exist in the parameter list then do NOT replace the
0251           % value. (see combine) If the user use a different syntax (he use
0252           % upper case letters) this value is put before the user value.
0253           % This function take ALWAYS the user value.
0254           pl_s = combine(pl_s, plist('yscale', sort_ao.(class_name).yscale));
0255         end
0256 
0257         % Plot always the second y-axes as a linear scale
0258         pl_s = set(pl_s, 'Yscale2', 'linear');
0259       end
0260 
0261       % Set x-, y-label
0262       xlabel(axes_h2, label_x1);
0263       ylabel(axes_h1, label_y1);
0264       ylabel(axes_h2, label_y2);
0265 
0266       out_line_h   = [out_line_h,   line_h1, line_h2];
0267       out_axes_h   = [out_axes_h,   axes_h1, axes_h2];
0268       out_figure_h = [out_figure_h, fig_h];
0269 
0270     %%%%%%%%%%   Plot real values   %%%%%%%%%%
0271     else
0272       [line_h1, axes_h1] = plot(real(sort_ao.(class_name).ao), line_spec, prop_val);
0273 
0274       axes_h2 = axes_h1;
0275       line_h2 = line_h1;
0276 
0277       % Set x-, y-label
0278       xlabel(axes_h1, [sort_ao.(class_name).xlabel_des ' [' xunits ']']);
0279       ylabel(axes_h1, [sort_ao.(class_name).ylabel_des ' [' yunits ']']);
0280 
0281       out_line_h   = [out_line_h,   line_h1];
0282       out_axes_h   = [out_axes_h,   axes_h1];
0283       out_figure_h = [out_figure_h, fig_h];
0284 
0285         % Do not set the xscale if it is set as a propertie/value pair
0286         if ~ismember('xscale', lower(prop_val))
0287           % If the 'key' exist in the parameter list then do NOT replace the
0288           % value. (see combine) If the user use a different syntax (he use
0289           % upper case letters) this value is put before the user value.
0290           % This function take ALWAYS the user value.
0291           pl_s = combine(pl_s, plist('xscale', sort_ao.(class_name).xscale));
0292         end
0293 
0294         % Do not set the yscale if it is set as a propertie/value pair
0295         if ~ismember('yscale', lower(prop_val))
0296           % If the 'key' exist in the parameter list then do NOT replace the
0297           % value. (see combine) If the user use a different syntax (he use
0298           % upper case letters) this value is put before the user value.
0299           % This function take ALWAYS the user value.
0300           pl_s = combine(pl_s, plist('yscale', sort_ao.(class_name).yscale));
0301         end
0302 
0303     end % if complex == true
0304 
0305     %%%%%%%%%%   Set Title     %%%%%%%%%%
0306     title (axes_h1, sort_ao.(class_name).title_str);
0307 
0308     %%%%%%%%%%   Set Title     %%%%%%%%%%
0309     grid(axes_h1, 'on');
0310     grid(axes_h2, 'on');
0311 
0312     %%%%%%%%%%   Set legend names   %%%%%%%%%%
0313     % Use the ao names for the legend
0314     if isempty(sort_ao.(class_name).legend_names)
0315       for jj = 1:length(line_h1)
0316 
0317         display_name = sort_ao.(class_name).ao(jj).name;
0318         display_name = ltpda_label(display_name);
0319         display_name = wrapLegendString(sprintf('%s', ltpda_label(display_name)), len_legend);
0320         set(line_h1(jj), 'DisplayName', display_name)
0321       end
0322       legend(axes_h1, 'toggle')
0323       % Use the legend names from the plist
0324     else
0325       legend(axes_h1, sort_ao.(class_name).legend_names);
0326     end
0327 
0328     %%%%%%%%%%   Set axes OR lineseries properties from the plist   %%%%%%%%%%
0329     for jj = 1:length(pl_s.params)
0330       p = pl_s.params(jj);
0331 
0332       [idx_b, idx_e, dummy, match] = regexp(p.key, '\d', 'once');
0333       p.key = strrep(p.key, match, '');
0334 
0335       % Check key to the axes property
0336       if isprop(line_h1, p.key)
0337         if strcmp(match, '1')
0338           set(line_h1, p.key, p.val);
0339         elseif strcmp(match, '2')
0340           set(line_h2, p.key, p.val);
0341         else
0342           set(line_h1, p.key, p.val);
0343           set(line_h2, p.key, p.val);
0344         end
0345       % Check key to the axes property
0346       elseif isprop(axes_h1, p.key)
0347         if strcmp(match, '1')
0348           set(axes_h1, p.key, p.val);
0349         elseif strcmp(match, '2')
0350           set(axes_h2, p.key, p.val);
0351         else
0352           set(axes_h1, p.key, p.val);
0353           set(axes_h2, p.key, p.val);
0354         end
0355       end
0356 
0357     end
0358 
0359   end
0360 
0361 
0362   %%%%%%%%%%   varargout{1} = line   handle   %%%%%%%%%%
0363   %%%%%%%%%%   varargout{2} = axes   handle   %%%%%%%%%%
0364   %%%%%%%%%%   varargout{3} = figure handle   %%%%%%%%%%
0365 
0366   if nargout == 0
0367   elseif nargout == 1
0368     varargout{1} = out_line_h;
0369   elseif nargout == 2
0370     varargout{1} = out_line_h;
0371     varargout{2} = out_axes_h;
0372   elseif nargout == 3
0373     varargout{1} = out_line_h;
0374     varargout{2} = out_axes_h;
0375     varargout{3} = out_figure_h;
0376   else
0377     error('### Unknown number of outputs.')
0378   end
0379 
0380 
0381 end % function varargout = iplot(varargin)
0382 
0383 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0384 %
0385 % DESCRIPTION: GETDEFAULTLIST retuns the default parameter list.
0386 %
0387 % CALL:        pl_default = getDefaultPL()
0388 %
0389 % HISTORY:     21-08-2007 Diepholz
0390 %                 Creation
0391 %
0392 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0393 function pl_default = getDefaultPL()
0394 
0395   pl_default = plist();
0396   pl_default = append(pl_default, 'complex_view', 'mag/deg');
0397 end
0398 
0399 
0400 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0401 %
0402 % DESCRIPTION: WRAPLEGENDSTRING wrap a legend string into multiple lines.
0403 %
0404 % CALL:        so = wrapLegendString(s, N)
0405 %
0406 % HISTORY:     21-08-2007 M Hewitson
0407 %                 Creation
0408 %
0409 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0410 function so = wrapLegendString(s, N)
0411   % get cells
0412   sc = wrapstring(s, N);
0413 
0414   so = sc{1};
0415 
0416   for j=2:length(sc)
0417     so = [so sprintf('\n%s', sc{j})];
0418   end
0419 end
0420 
0421 
0422 
0423

Generated on Mon 03-Sep-2007 12:12:34 by m2html © 2003