Need help with data store memory block of simulink
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am using some global variables in .m file so that their values generated in previous time step can automatically be used in the code. I am not getting any simple video on the above ..whaterver I have learned from the internet, I have applied to make a simulink model...could anyone suggest me what m I doing wrong?
some variables in the model are defined as model variables...like As, Af,Ca,Cm,sicrs,sicrf,Ms Mf...In actual .m file i used another .m file (prop.m) to define these variables (as they are constant parameters) while calling them in different fuction files.
0 commentaires
Réponses (1)
Amish
le 5 Fév 2025
Hi Nisha,
Using global variables in MATLAB and Simulink can be a bit tricky, especially if you're trying to maintain state across time steps in a simulation. While dealing with global variables in scenarioes such as yours I would recommend that you follow certain guidelines to help maintain the workspace variables clearly.
Always, declare global variables using the global keyword in each function or script where you want to access them. Before running the Simulink model, ensure that all global variables are initialized. You can do this in the MATLAB base workspace or, preferably, in an initialization script. This will allow you to use model callbacks (e.g., InitFcn) to run initialization scripts automatically when the model starts.
If you have constant parameters like As, Af, etc., you can initialize them in the Simulink model using the Model Workspace or Configuration Parameters under Model Properties.
Hope these help!
0 commentaires
Voir également
Catégories
En savoir plus sur Event Functions dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!