Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Programmatic GUI pushbutton callback
Date: Thu, 26 Jun 2008 16:15:04 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 55
Message-ID: <g40fa8$omg$1@fred.mathworks.com>
References: <g40e4n$aiq$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1214496904 25296 172.30.248.37 (26 Jun 2008 16:15:04 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 26 Jun 2008 16:15:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 939004
Xref: news.mathworks.com comp.soft-sys.matlab:476012



"Kris Ezra" <sharpshooter1405@yahoo.com> wrote in message
<g40e4n$aiq$1@fred.mathworks.com>...
> 
> I am building a GUI to interface with a MATLAB model and, 
> in the interest of maintaining GUI variables in the 
> workspace and accessible, I have opted to create it 
> programmatically and not in function form instead of with 
> GUIDE.
> 
> The problem I have is that, while I can easily create the 
> GUI and push buttons with code like
> 
> startbutton = 
> uicontrol(panel3,'Style','pushbutton','String','Create 
> Scenario',...
>     'Position',[40, 80, 120, 40], 'BackgroundColor', 
> [0.8,0.8,0.8]);  
> 
> I cannot find any way to set the button callback.  I would 
> rather not use custom functions (which shouldnt matter 
> since the main GUI is just written in a script file) and I 
> cant find a solution.
> 
> As a simple test, I would like to have "startbutton" open a 
> PDF file.
> 
> I have tried something to the effect of set
> (startbutton, 'Callback', open usersguide.pdf) but this 
> does not work.  What else can I do to code button callbacks?


I should be more specific:

The "best" thing to do is this:

 uicontrol(panel3,'Style','pushbutton','String','Create 
 Scenario',...
     'Position',[40, 80, 120, 40], 'BackgroundColor', 
 [0.8,0.8,0.8],...
'callback',@button1_callback); 

and at the end of your file:


function button1_callback(src,eventdata)
hanldles=guidata(src)

open usersguide.pdf

guidata(src,handles)