How to add a new MATLAB variable to the list of predefined parameters?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Ambareesh Rathi
am 24 Apr. 2017
Kommentiert: Sebastian Castro
am 25 Apr. 2017
I have been trying to modify the existing model 'ssc_refrigeration', such that it also enables us to display the total compressor power. For the same, I have created a MATLAB variable named 'TCP', which would do the following work (summing up the instantaneous powers and giving the final total compressor power).
The problem is, for it (variable 'TCP') to run and give the total compressor power, I have to save it every time in the list of already existing parameters (predefined parameters) in the MATLAB workspace (with an initial value of zero), before running the model. If I don't do this, it shows an error that the variable 'TCP' is undefined. Once I save it in the workspace, it runs perfectly fine but it disappears again after I restart the model. So I have to repeat the above steps again for making it run.
Is there a way to save it (the new variable 'TCP') in the list of predefined parameters, without having to add again and again?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/163270/image.jpeg)
0 Kommentare
Akzeptierte Antwort
Sebastian Castro
am 24 Apr. 2017
For sure. You can add callbacks to your model to execute code when the model is loaded, initialized, simulated, saved, etc.
If you open up the ssc_refrigeration model, go to File - Model Properties - Model Properties, and then go to the Callbacks tab, you'll see there's already a bunch of code in the "PreLoadFcn" callback section.
In this section, you can either add a MATLAB command that defines TCP or you can define this variable in a script/MAT-file and call/load it accordingly.
Sebastian
2 Kommentare
Sebastian Castro
am 25 Apr. 2017
That makes sense. simlog_W is a post-simulation log, so it won't be created until after the simulation is completed.
If it makes sense, you can move the creation of TCP to one of the post-simulation callbacks, e.g., "StopFcn"... else, if you need the logs before simulation, the best bet would be to save the simlog_w variable to a MAT-file and load it on startup as needed.
Again, this depends on the data dependencies you have.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Prepare Model Inputs and Outputs 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!