-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdynamicSlider.m
More file actions
33 lines (29 loc) · 1012 Bytes
/
dynamicSlider.m
File metadata and controls
33 lines (29 loc) · 1012 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
function[h] = dynamicSlider(varargin)
% DYNAMICSLIDER Creates a new slider uicontrol that executes its callback
% continuously.
%
% See also UICONTROL.
callbackIndex = find(strcmp(varargin, 'Callback'));
if isempty(callbackIndex)
throw(MException('dynamicSlider:IllegalArgument', ['Must provide a '...
'callback. If you do not need a callback function, use '...
'''uicontrol'' with ''Style'' as ''slider''.']));
end
callback = varargin{callbackIndex+1};
varargin(callbackIndex:callbackIndex+1) = [];
styleIndex = find(strcmp(varargin, 'Style'));
if ~isempty(styleIndex)
if ~strcmp(varargin{styleIndex+1}, 'slider')
disp('''Style'' must be ''slider''. Ignoring provided ''Style''');
end
varargin(styleIndex:styleIndex+1) = [];
end
h = uicontrol('Style', 'slider');
for i=1:2:size(varargin, 2)
name = varargin{i};
value = varargin{i+1};
set(h, name, value);
end
listener = handle.listener(h, 'ActionEvent', callback);
setappdata(h, 'listener', listener);
end