Path: news.mathworks.com!not-for-mail
From: "Clay Ross" <clayton.e.ross@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: User defined length of pop-up menu GUI
Date: Thu, 20 Aug 2009 18:56:19 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 40
Message-ID: <h6k68j$3l7$1@fred.mathworks.com>
References: <h6k3ti$1a1$1@fred.mathworks.com> <h6k5ce$688$1@fred.mathworks.com>
Reply-To: "Clay Ross" <clayton.e.ross@gmail.com>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1250794579 3751 172.30.248.38 (20 Aug 2009 18:56:19 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 20 Aug 2009 18:56:19 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1941000
Xref: news.mathworks.com comp.soft-sys.matlab:564860

"Andy " <theorigamist@gmail.com> wrote in message <h6k5ce$688$1@fred.mathworks.com>...
> "Clay Ross" <clayton.e.ross@gmail.com> wrote in message <h6k3ti$1a1$1@fred.mathworks.com>...
> > Hello.
> > 
> > If I have an array of 1:n, how can I construct a pop-up menu with selections of 1:n? The user will be responsible for determining the value of "n." I just learned how to program GUI's in MATLAB today, so hopefully this isn't hard to do.
> > 
> > Thanks!
> > 
> > Clay
> 
> % here is an example

That is perfect! Thanks a lot Andy!
> 
> function testgui
> 
> f=figure;
> 
> edit1=uicontrol('Parent',f,...
>     'Style','edit',...
>     'Units','normalized',...
>     'Position',[.2 .6 .2 .1],...
>     'Callback',{@edit1_Callback});
> 
> pop1=uicontrol('Parent',f,...
>     'Style','popupmenu',...
>     'Units','normalized',...
>     'Position',[.2 .2 .2 .1],...
>     'String','Enter a number');
> 
>     function edit1_Callback(src,eventdata)
>         n=get(edit1,'String');
>         n=str2double(n);
>         set(pop1,'String',num2cell(1:n)');
>     end
> 
> end
> 
> % Also see the following for lots of answers to common questions about GUIs:
> % http://www.mathworks.com/matlabcentral/fileexchange/24861