Path: news.mathworks.com!not-for-mail
From: "Giacomo " <bigbig1982@hotmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Plot workspace data with GUI
Date: Sun, 26 Jul 2009 07:16:05 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 38
Message-ID: <h4gvrl$mh8$1@fred.mathworks.com>
References: <h4c1ab$4fp$1@fred.mathworks.com> <17858889.32139.1248434741394.JavaMail.jakarta@nitrogen.mathforum.org>
Reply-To: "Giacomo " <bigbig1982@hotmail.com>
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 1248592565 23080 172.30.248.37 (26 Jul 2009 07:16:05 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 26 Jul 2009 07:16:05 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1880541
Xref: news.mathworks.com comp.soft-sys.matlab:558363


Bill August <hui.song@beds.ac.uk> wrote in message <17858889.32139.1248434741394.JavaMail.jakarta@nitrogen.mathforum.org>...
> > Hello all,
> > in my Simulink model I have a "To Workspace" block
> > called "Test_Data" where I store the simulation data
> > to the base workspace. I wish that, once the
> > simulation is finished and the data are registered
> > into the workspace, clicking on a button on my GUI it
> > pop-up the graph of "Test_Data" with time. It seems
> > so easy but its two days I cannot solve it, matlab
> > keeps giving me errors like "Undefined function or
> > variable 'Test_Data'.
> > The code for the Plot button callback is:
> > 
> > function plot_button_Callback(hObject, eventdata,
> > handles)
> > axes(handles.axes1)
> > options = simset('SrcWorkspace','base');
> > plot(Test_Data, 'DisplayName', 'Test_Data',
> > 'YDataSource', 'Test_Data');
> > 
> > Can someone help me out solving this? Thank you in
> > advance^^
> > 
> > Giacomo
> Hi Giacomo,
> As you function "plot_button_Callback" and workspace is not in the same stack. You need to either capture the data from the workspace to your function, or execute you plot function in the workspace.
> The direct way is to use "evalin"
> 
> If you want to capture the data from the workspace,
> Test_Data = evalin('base', 'Test_Data') ; 
> plot(Test_Data, 'DisplayName', 'Test_Data', 'YDataSource', 'Test_Data');
> 
> Or you can execute your plot function in the workspace,
> evalin('plot(Test_Data, ''DisplayName'', ''Test_Data'', ''YDataSource'', ''Test_Data'');') ;
> 
> These solutions are not the best way to organize the data, you may try to save the data to your local handle. i.e. "UserData" of the GUI handle.

Thank you Bill, it solves my problem :)