Prev: Function calling
Next: numerical errors using eig()
From: CyberFrog on 13 Mar 2010 08:29 Hi, I would like to be able to get a value of a checkbox by using a the name of the checkbox by a different string i.e. mycheckbox1 = = uicontrol(f,'Style','checkbox',... 'String','1',... 'Value',1,'Position',[50 275 30 20]); mycheckbox2 = = uicontrol(f,'Style','checkbox',... 'String','1',... 'Value',1,'Position',[50 275 30 20]); now instead of saying getvalue = get(mycheckbox1,'value') then the same but with 2 I would like to replace mycheckbox with a generic string name instead so I can look for each checkbox value in a loop i.e. for i=1:2 mystring = sprintf('checkbox%s\n',i); get(mystring,'value'); end Obviosuly this doesn't seem to work alone. Thanks in advance
From: Matt Fig on 13 Mar 2010 13:25 Rather than using strings, I would tend to use vectors, something like this: function [] = examp() f = figure; S.mycheckbox(1) = uicontrol(f,'Style','checkbox',... 'String','0',... 'Value',0,'Position',[50 275 30 20]); S.mycheckbox(2) = uicontrol(f,'Style','checkbox',... 'String','1',... 'Value',1,'Position',[50 290 30 20]); S.mypushbutton = uicontrol(f,'Style','pushbutton',... 'string','Pushme',... 'callback',{@callb,S}); function [] = callb(H,E,S) for ii=1:2 V(ii) = get(S.mycheckbox(ii),'value'); % Or V = get(S.mycheckbox(:),'value') -- no loop needed. end V % Show on command line. Now if you really want to use strings, you could use the 'tag' property of the objects and couple this with FINDOBJ to access the handle.
From: CyberFrog on 14 Mar 2010 16:59 "Matt Fig" <spamanon(a)yahoo.com> wrote in message <hngla5$goi$1(a)fred.mathworks.com>... > Rather than using strings, I would tend to use vectors, something like this: > > > > function [] = examp() > > f = figure; > S.mycheckbox(1) = uicontrol(f,'Style','checkbox',... > 'String','0',... > 'Value',0,'Position',[50 275 30 20]); > > S.mycheckbox(2) = uicontrol(f,'Style','checkbox',... > 'String','1',... > 'Value',1,'Position',[50 290 30 20]); > S.mypushbutton = uicontrol(f,'Style','pushbutton',... > 'string','Pushme',... > 'callback',{@callb,S}); > > function [] = callb(H,E,S) > > for ii=1:2 > V(ii) = get(S.mycheckbox(ii),'value'); > % Or V = get(S.mycheckbox(:),'value') -- no loop needed. > end > V % Show on command line. > > > > Now if you really want to use strings, you could use the 'tag' property of the objects and couple this with FINDOBJ to access the handle. Thanks alot Matt, I have resorted to using the vectors instead works perfect! CF
|
Pages: 1 Prev: Function calling Next: numerical errors using eig() |