comparison m-toolbox/m/gui/ltpdv/callbacks/ltpdv_calc_btn.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f0afece42f48
1 function ltpdv_calc_btn(varargin)
2 % LTPDV_CALC_BTN called when one of the calculator buttons is pushed.
3 %
4 % M Hewitson 22-04-08
5 %
6 % $Id: ltpdv_calc_btn.m,v 1.1 2008/05/11 10:38:43 hewitson Exp $
7 %
8
9 % Handles
10 myh = varargin{1};
11 mainfig = varargin{end-1};
12 nins = varargin{end};
13
14 % Get operation
15 op = get(myh, 'String');
16
17 % Get selected objects
18 objs = ltpdv_get_selected_objs(mainfig);
19 Nobjs = length(objs);
20
21 if Nobjs < nins
22 error('### Please select two objects');
23 end
24
25 % check objects are all AOs
26 for j=1:Nobjs
27 if ~isa(objs{j}, 'ao')
28 error('### Please select only AOs for math calculations');
29 end
30 end
31
32 % Loop over AOs
33 n = 1;
34 res = {};
35 while n <= length(objs)
36 % operate on two objects
37 switch nins
38 case 1
39 res = [res {feval(op, objs{n})}];
40 case 2
41 if isempty(res)
42 res = feval(op, objs{n}, objs{n+1});
43 n = n + 1;
44 else
45 res = feval(op, res, objs{n});
46 end
47 end
48 n = n + 1;
49 end
50
51 if nins == 2
52 res = {res};
53 end
54
55 % Add this result to the object list
56 objs = getappdata(mainfig, 'LTPDAobjects');
57 if ~isempty(res)
58 setappdata(mainfig, 'LTPDAobjects', [objs res]);
59 % Refresh object list
60 ltpdv_refresh_object_list(mainfig);
61 end
62
63
64 % END