MATLAB: How to plot struct data

plotsimoutsimulinkstruct datato workspace

Hi, I am running a simulation in Simulink and using a to workspace block,to view the results also in the workspace. what I get as results in my workspace is an output with the name of my block, "simout", which is a 1*1 struct and a "tout" which is double. how can I plot my "simout"?

Best Answer

The simout structure has simout.signals, simout.time and simout.blockName fields. The simout.signals field also has a simout.signals.values field, which holds your sampled data.
Further, if you selected 'Structure With Time' in your 'To Workspace' block, then the time field will be populated and the easiest way to plot it is like this:
>> plot(simout.time,simout.signals.values)
Otherwise, simout.time is left empty and you should just use the tout vector for your time variable like this:
>> plot(tout,simout.signals.values)