Simulink: Save the max value of a system and update it every time it gets a new value
5 次查看(过去 30 天)
显示 更早的评论
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1403969/image.png)
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
0 个评论
回答(1 个)
Manoj Mirge
2023-8-18
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Model, Block, and Port Callbacks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!