Simulink simulation that uses data over all time

2 views (last 30 days)
Hi guys,
So the simulation i want is a moving body that collects data as it moves. I then want to use the newly collected data AND the data collected in the past to decide the next move.
The problem i'm having is how to do this in simulink as it runs step by step on just the newly collected data - perhaps the easiet way is to write to and then read from a matlab workspace?
The current solution I have is using a matlab S funtion in the simulink model. It works but it runs quite slowly and I feel like there must be an easier way to do this.
I was thinking perhaps I could run the simulation step-by step in the loop of matlab script but im not sure if there is a way to continue a simulation from where it left off and it would be better to have it running continously.
Also if someone does know a solution for this type of sim perhaps they also know a way i can have two parts of the simulation running asyncronously? This is less important but would also be useful.
Thanks for taking your time to read this.

Answers (1)

Karan Singh
Karan Singh on 7 Sep 2023
Hi Dave,
From what I understand, you have already tried using a MATLAB S-function in the Simulink model but found it to be slow and are seeking an easier and more efficient solution.
There are a few approaches you can consider:
  1. Simulink with MATLAB Function Block: This block allows you to write custom MATLAB code that can access and update variables continuously during simulation.
  2. MATLAB Workspace: Another approach is to write the collected data to the MATLAB workspace during simulation and read it back in for subsequent iterations. You can use the "To Workspace" block in Simulink to save the data to a variable in the MATLAB workspace and then use a MATLAB script or function to process the data.
  3. Stateflow: If you need more advanced control logic and state-based decision-making, you can consider using Stateflow in Simulink.
Regarding running the simulation step-by-step in a loop within a MATLAB script, it is possible to do so using the sim function in MATLAB. However, this approach may not be as efficient as running the simulation continuously within Simulink.
To have different parts of the simulation running asynchronously, you can consider using parallel computing techniques in MATLAB using the parallel computing toolbox.
Attached below are some documentation links that you may find helpful:
Hope this helps!

Categories

Find more on Simulink Functions in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!