How to add a new MATLAB variable to the list of predefined parameters?
2 ビュー (過去 30 日間)
古いコメントを表示
Ambareesh Rathi
2017 年 4 月 24 日
コメント済み: Sebastian Castro
2017 年 4 月 25 日
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?
0 件のコメント
採用された回答
Sebastian Castro
2017 年 4 月 24 日
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 件のコメント
Sebastian Castro
2017 年 4 月 25 日
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.
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!