how do I restore cleared variables in Simulink simscape example?

1 vue (au cours des 30 derniers jours)
재현
재현 le 13 Nov 2024
Commenté : 재현 le 13 Nov 2024
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 commentaires
Cris LaPierre
Cris LaPierre le 13 Nov 2024
Déplacé(e) : Cris LaPierre le 13 Nov 2024
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
재현
재현 le 13 Nov 2024
Thank you so much for your detailed answer. I solved the problem with your help.

Connectez-vous pour commenter.

Réponse acceptée

Angelo Yeo
Angelo Yeo le 13 Nov 2024
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.
  1 commentaire
재현
재현 le 13 Nov 2024
Thanks for your quick reply. It took me a while to find "File Explorer", but I learned something good.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Two-Phase Fluid Library dans Help Center et File Exchange

Produits


Version

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by