Path: news.mathworks.com!newsfeed-00.mathworks.com!news.kjsl.com!news.glorb.com!news2.glorb.com!tr22g12.aset.psu.edu!news.mathforum.org!not-for-mail
From: Bill August <hui.song@beds.ac.uk>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Plot workspace data with GUI
Date: Fri, 24 Jul 2009 07:25:10 EDT
Organization: The Math Forum
Lines: 35
Message-ID: <17858889.32139.1248434741394.JavaMail.jakarta@nitrogen.mathforum.org>
References: <h4c1ab$4fp$1@fred.mathworks.com>
NNTP-Posting-Host: nitrogen.mathforum.org
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: support1.mathforum.org 1248434741 30314 144.118.30.135 (24 Jul 2009 11:25:41 GMT)
X-Complaints-To: news@news.mathforum.org
NNTP-Posting-Date: Fri, 24 Jul 2009 11:25:41 +0000 (UTC)
Xref: news.mathworks.com comp.soft-sys.matlab:558077


> 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.