Thread Subject: converting the get command for gui's to a string

Subject: converting the get command for gui's to a string

From: CyberFrog

Date: 13 Mar, 2010 13:29:07

Message: 1 of 3

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

Subject: converting the get command for gui's to a string

From: Matt Fig

Date: 13 Mar, 2010 18:25:09

Message: 2 of 3

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.

Subject: converting the get command for gui's to a string

From: CyberFrog

Date: 14 Mar, 2010 20:59:07

Message: 3 of 3

"Matt Fig" <spamanon@yahoo.com> wrote in message <hngla5$goi$1@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

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com