Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: User defined length of pop-up menu GUI
Date: Thu, 20 Aug 2009 18:41:18 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 37
Message-ID: <h6k5ce$688$1@fred.mathworks.com>
References: <h6k3ti$1a1$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1250793678 6408 172.30.248.35 (20 Aug 2009 18:41:18 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 20 Aug 2009 18:41:18 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1895050
Xref: news.mathworks.com comp.soft-sys.matlab:564850

"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

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