John
John

Reputation: 3460

How can I save output from Simulink?

I'm a student learning to use MATLAB. For an assignment, I have to create a simple state machine and collect some results. I'm used to using Verilog/Modelsim, and I'd like to collect data only when the state machine's output changes, which is not necessarily every time/sample period.

Right now I have a model that looks like this:

RequestChart ----> ResponseChart ----> Unit Delay Block --> (Back to RequestChart)
               |                  |
               ------------------------> Mux --> "To Workspace" Sink Block

I've tried setting the sink block to save as "Array" format, but it only saves 51 values. I've tried setting it to "Timeseries", but it saves tons of zero values.

Can someone give me some suggestions? Like I said, MATLAB is new to me, please let me know if I need to clarify my question or provide more information.

Edit: Here's a screen capture of my model: enter image description here

Upvotes: 0

Views: 2670

Answers (2)

Phil Goddard
Phil Goddard

Reputation: 10762

Generally Simulink will output a sample at every integration step. If you want to only output data when a particular event occurs -- in this case only when some data changes -- then do the following,

  • run the output of the state machine into a Detect Change block (from the Logic and Bit Operations library)
  • run that signal into the trigger port of a Triggered Subsystem.
  • run the output of the state machine into the data port of the Triggered Subsystem.
  • inside the triggered subsystem, run the data signal into a To Workspace block.

Data will only be saved at time point that the trigger occurs, i.e. when your data changes.

Upvotes: 2

rayryeng
rayryeng

Reputation: 104493

In your Simulink window, make sure the Relative Tolerance is small so that you can generate many more points in between your start and ending time. Click on the Simulation option at the top of the window, then click on Model Configuration Parameters.

enter image description here

From there, change the Relative Tolerance to something small... like 1e-10. After that, try running your simulation again. You should have a lot more points in your output array that you can now save.

enter image description here

Upvotes: 1

Related Questions