Home > m > gui > ltpdv > callbacks > ltpdv_calc_btn.m

ltpdv_calc_btn

PURPOSE ^

LTPDV_CALC_BTN called when one of the calculator buttons is pushed.

SYNOPSIS ^

function ltpdv_calc_btn(varargin)

DESCRIPTION ^

 LTPDV_CALC_BTN called when one of the calculator buttons is pushed.
 
 M Hewitson 22-04-08
 
 $Id: ltpdv_calc_btn.m,v 1.1 2008/05/11 10:38:43 hewitson Exp $

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function ltpdv_calc_btn(varargin)
0002 % LTPDV_CALC_BTN called when one of the calculator buttons is pushed.
0003 %
0004 % M Hewitson 22-04-08
0005 %
0006 % $Id: ltpdv_calc_btn.m,v 1.1 2008/05/11 10:38:43 hewitson Exp $
0007 %
0008 
0009 % Handles
0010 myh     = varargin{1};
0011 mainfig = varargin{end-1};
0012 nins    = varargin{end};
0013 
0014 % Get operation
0015 op = get(myh, 'String');
0016 
0017 % Get selected objects
0018 objs = ltpdv_get_selected_objs(mainfig);
0019 Nobjs = length(objs);
0020 
0021 if Nobjs < nins
0022    error('### Please select two objects');
0023 end
0024 
0025 % check objects are all AOs
0026 for j=1:Nobjs
0027    if ~isa(objs{j}, 'ao')
0028       error('### Please select only AOs for math calculations');
0029    end
0030 end
0031 
0032 % Loop over AOs
0033 n   = 1;
0034 res = {};
0035 while n <= length(objs)   
0036    % operate on two objects
0037    switch nins
0038       case 1
0039          res = [res {feval(op, objs{n})}];
0040       case 2
0041          if isempty(res)
0042             res = feval(op, objs{n}, objs{n+1});
0043             n = n + 1;
0044          else
0045             res = feval(op, res, objs{n});            
0046          end
0047    end
0048    n = n + 1;
0049 end
0050 
0051 if nins == 2
0052    res = {res};
0053 end
0054 
0055 % Add this result to the object list
0056 objs = getappdata(mainfig, 'LTPDAobjects');
0057 if ~isempty(res)
0058    setappdata(mainfig, 'LTPDAobjects', [objs res]);
0059    % Refresh object list
0060    ltpdv_refresh_object_list(mainfig);
0061 end
0062 
0063 
0064 % END

Generated on Mon 08-Sep-2008 13:18:47 by m2html © 2003