Simulink "globals" not working as expected

1 view (last 30 days)
I have an open loop simulink model. It runs one time step and stops. I would like some of the intermediate data for run i to be available in run i+1. I have tried to use Data Stores. I write the intermediate data to them on run i and then have a read on i+1 that tries to use them. All that happens is it passes back the initialzed value each time. Is there a way to use Data Stores as I am attempting to use? If not, can you suggest an alternative? Thanks!
  6 Comments
Walter Roberson
Walter Roberson on 1 Aug 2022
next simulation run is my understanding
Daniel Harman
Daniel Harman on 1 Aug 2022
Next simulation run. I don't bring simulik down between runs. To give more context to what i'm attempting to do, an external program passes data to my simulink model and it runs for one time step and passes data back to that external program and stops processing until the external program passes data again. My simulink models the dynamics and I need to keep the previous dynamics state in order to calculate the next one once the external function passes data over again. I tried what was suggested and I'm still not getting the data saved. I'm enclosing some pictures of my blocks, which might point toward what I'm doing wrong. Thank you very much for your help so far!

Sign in to comment.

Accepted Answer

Fangjun Jiang
Fangjun Jiang on 1 Aug 2022
"global" data store is not meant for saving data between different simulation runs.
Refer to this:
web(fullfile(docroot, 'simulink/ug/decide-how-to-save-block-states-and-simulation-operating-points.html?s_tid=doc_srchtitle'))
or
  1 Comment
Daniel Harman
Daniel Harman on 4 Aug 2022
The above link helped. I can initialize the functions using the "out" structure from a simulink run. Ultimately my problem was the intialization being incapable of using logic (if ~exist(out) use_initial_values else use_out end). Instead, I had to initialize "out" before running simulink and the initization feature had no problem. The first time run it would grab the initial run values. The next time, it would grab the last output simulink vectors. Simulink is a particularly finiky and frustrating system to use. Everything might be intuitive after a year of using it.

Sign in to comment.

More Answers (0)

Categories

Find more on Event Functions in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!