How to add a new MATLAB variable to the list of predefined parameters?

2 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

Sebastian Castro
Sebastian Castro il 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.
Look at this section in the documentation for more info.
Sebastian
  2 Commenti
Ambareesh Rathi
Ambareesh Rathi il 25 Apr 2017
Hi Sebastian,
Thank you for your reply.
I tried doing this. Actually, I want 'TCP' to perform the operation 'sum(simlog_W)' and not fixing a constant value to it (which is the case with all the other predefined variables). Here, 'simlog_W' is the instantaneous power.
If I add 'TCP = sum(simlog_W)' in the "PreLoadFcn" or call/load this variable by saving it in a script, either way it is showing "undefined function or variable 'simlog_W'".
How should I go about resolving this? Any leads will be much appreciated!
- Ambareesh
Sebastian Castro
Sebastian Castro il 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.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Prepare Model Inputs and Outputs in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by