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