How to add a new MATLAB variable to the list of predefined parameters?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Ambareesh Rathi
el 24 de Abr. de 2017
Comentada: Sebastian Castro
el 25 de Abr. de 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 comentarios
Respuesta aceptada
Sebastian Castro
el 24 de Abr. de 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 comentarios
Sebastian Castro
el 25 de Abr. de 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.
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!