how do I restore cleared variables in Simulink simscape example?
27 views (last 30 days)
Show older comments
I am studying the example file from Two-Phase Fluid Refrigeration of simscape .
clearing variables before running the code for the first time is fine.
but if I clear variables after running the code and run it agian, an error occurs saying that there is no information.
Are the variables created only when running for the first time?
and how do I restore cleared variables in Simulink simscape example?
Below is a video of my situation.
Thank you.
2 Comments
Cris LaPierre
on 13 Nov 2024 at 4:18
Moved: Cris LaPierre
on 13 Nov 2024 at 4:19
There is a pre-load function included in the model properties. This runs when the model is opened. The simplest solution is to close the model and reopen it. Otherwise, navigate to Model Properties and copy the pre-load function code to a script and run it there.
load r134aPropertyTables
% Refrigerant:
initial_pressure = 0.6; % MPa
initial_quality = 0.05;
% Environment:
environment_temperature = 293; % K
natural_convection_coefficient = 20; % W/m^2/K
% Controller:
target_temperature = 277; % K
temperature_delta = 2; % K
% Compressor:
commanded_mass_flow = 0.004; % kg/s
controller_time_constant = 20; % s
% Expansion valve:
min_throat_area = 0.1; % mm^2
max_throat_area = 1.5; % mm^2
min_throat_temperature = 270; % K
max_throat_temperature = 250; % K
% Heat exchangers:
condenser_length = 30; % m
evaporator_length = 30; % m
fin_area = 1; % m^2
fin_convection_coefficient = 150; % W/m^2/K
% Pipes:
pipe_diameter = 0.01; % m
pipe_thickness = 0.0005; % m
% Refrigerator compartment:
interior_surface_area = 4.5; % m^2
exterior_surface_area = 6; % m^2
foam_thickness = 0.03; % m
% Material properties:
copper_density = 8940; % kg/m^3
copper_specific_heat = 390; % J/kg/K
copper_conductivity = 400; % W/m/K
foam_conductivity = 0.03; % W/m/K
You can learn more about model callbacks here: https://www.mathworks.com/help/simulink/ug/model-callbacks.html
Accepted Answer
Angelo Yeo
on 13 Nov 2024 at 4:10
In the shipped example, Two-Phase Fluid Refrigeration - MATLAB & Simulink - MathWorks 한국, the Simulink model has "PreLoadFcn" callback.
In order to define the variables, you can run the script in the "PreLoadFcn" callback manually, or you can open the "TwoPhaseFluidRefrigeration.slx" file to "automatically" run the PreLoadFcn callback script.
More Answers (0)
See Also
Categories
Find more on Two-Phase Fluid Library in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!