Thread Subject: Plot workspace data with GUI

Subject: Plot workspace data with GUI

From: Giacomo

Date: 24 Jul, 2009 10:10:19

Message: 1 of 3

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

Subject: Plot workspace data with GUI

From: Bill August

Date: 24 Jul, 2009 11:25:10

Message: 2 of 3

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

Subject: Plot workspace data with GUI

From: Giacomo

Date: 26 Jul, 2009 07:16:05

Message: 3 of 3

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 :)

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
gui Giacomo 24 Jul, 2009 06:14:03
workspace Giacomo 24 Jul, 2009 06:14:03
plot Giacomo 24 Jul, 2009 06:14:03
rssFeed for this Thread

Contact us at files@mathworks.com