Simulink "globals" not working as expected

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

It looks to me as if PostLoadFcn callback might be the appropriate place to initialize the contents of the global variables the first time. I suspect that you are possibly using InitFcn callback at the moment
Unfortunately, I can't find that callback on the Data Store list of callbacks.
You would attach it to the model itself. Load the model, have the model PostLoadFcn callback set the initial values for the Data Store
First, please clarify "run i", "run i+1" is "runs one time" or "runs one time step"? "i+1" is the next simulation run, or the next simulation time step?
next simulation run is my understanding
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

"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

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

Products

Release

R2022a

Community Treasure Hunt

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

Start Hunting!