0

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

2
  • The to workspace block should do the trick. Could you add a screenshot of (the part of) your model where the variable(s) get(s) saved, so we can see if the block itself is correct? Commented Mar 10, 2015 at 21:47
  • @WouterKuijsters is that image helpful? Commented Mar 10, 2015 at 22:26

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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

4 Comments

I changed Relative tolerance to 1e-10 and kept the sink block save format as "Array". I re-ran the simulation (with "500" and "5000" for simulation stop time) and still got only 51 values. The workspace shows the variable "simout" with value "51x8 double" and min "0" and max "1".
@John - Weird... can we get a copy of your Simulink model so we can try things out?
Since you have a discrete time model, changing the relative tolerance will have no effect. You are getting 51 output point because by default the maximum step size (which is what the model will be taking in this case) is (Stop Time - Start Time)/50, i.e. Simulink is hard coded to take 50 steps (giving you 51 time points including t=0) in this case. To get more points (in this specific model), either pick a fixed-step solver and specify an appropriate sample rate, or choose any solver (although for speed you want fixed-step discrete) and set an appropriate sample rate in the Unit Delay block.
@PhilGoddard - Thanks! Good to know. Hope the OP can take that and run with it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.