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

Generated on Thu 01-Nov-2007 09:42:34 by m2html © 2003