Filter löschen
Filter löschen

Simulink: Save the max value of a system and update it every time it gets a new value

5 Ansichten (letzte 30 Tage)
I have a car which is driving with a constant speed. To go from 0 till 100kmh it need 20sec. I could represent it like this in simulink:
Here I gave as input 10 kmh has to be reach and as you see it need 2 Sec to reach it:
But I want that when I run the simulink again (with 10 again as input) it goes from 10 to 20. I tried the block max to get the actual max from the system (10 in this case) to give it add it to the new input to get 20 but the "max" block provides the same function of the time and not a value (Scalar).
Does anyone have an Idea this Issue? or it is a matter of how I am simulating it?
Some explanation from the model: the first saturation is to keep the speed between 0 and 100, the second one is for the speed (+-100/20). the integrator linited is to limit the integral between 0 and 100
Thanks in advance

Antworten (1)

Manoj Mirge
Manoj Mirge am 18 Aug. 2023
I understand you want to collect the maximum speed value from the model simulation and next time when you run the simulation, you would like to have access to maximum speed from previous simulation without changing the Simulink model.
You can achieve this workflow using the variables from the model workspace. Please refer to the below link to read more about the model workspace:
You can manipulate model workspace variables using MATLAB commands on a Simulink.Workspace variable. Please refer to the following documentation for the examples of how to access model workspace variable from MATLAB programmatically:
Since you want to change the variable’s value after end of every simulation, you may place the code that sets model workspace variable in the “StopFcn” callback of the model.
Kindly refer to the below attached link to read more about the “StopFcn” callback:
I hope this helps.


Mehr zu Model, Block, and Port Callbacks finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by