How to add a new MATLAB variable to the list of predefined parameters?
조회 수: 2 (최근 30일)
이전 댓글 표시
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
채택된 답변
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개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Prepare Model Inputs and Outputs에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!