MATLAB: Get results from simulink and plot in GUI

guiguidesimulink

I would like to get the results from my simulink model and plot in the GUI, but I do not know how it can be done. I input a series of data x to my simulink model, and simulate series of data y. I just want to plot the data x (input data) against the time step, and another plot for output data y against the time step.
Can anyone please provide or explain to me how and what are the program should I write in GUI "plot push button"??
I am new in MATLAB.

Best Answer

There are two way to get simulink simulation result outside the simulink.
1. Using To WorkSpace block:
Save the simulation data to base workspace using Sinks/ToWorkspace block (See here). Once simulation is complete and data is saved to matlab workspace, you can read & plot the data using m-script.
2. Using listener callback:
Create a callback function for the port whos data you want to access. Register this callback function with event listener. Advantage of using this method is that, you can access and plot the simulation data at run time (when the model is running).
See a good example here.