Effacer les filtres
Effacer les filtres

Load external file in ssc block Simscape

61 vues (au cours des 30 derniers jours)
Moritz
Moritz le 2 Août 2024 à 12:27
Commenté : Yifeng Tang le 7 Août 2024 à 19:01
I build a "liquid valve" component (.ssc file) in Simscape which includes a dropdown menu to select different valve types. The parameters for each valve are stored as a structure in a separated .m file. Depending on which valve is selected, I would like to "load" the corresponding values into my "liquid valve" component (.ssc file). Similar to the "Thermal Liquid Properties (TL)" component which loads an external file depending on the selected fluid.
How do I "load/import" my external .m file (structure) into my simscape component?
  1 commentaire
Yifeng Tang
Yifeng Tang le 7 Août 2024 à 19:01
My initial thoughts are to put a mask on the Simscape component(s), and use set_params to pull the values from the data source into the mask.

Connectez-vous pour commenter.

Réponses (1)

Shishir Reddy
Shishir Reddy le 5 Août 2024 à 7:11
Hi moritz
As per my understanding, you would like to “load” the corresponding values into the “liquid valve” component depending upon the valve selected.
For this, the simscape component should be modified as follows
parameters
% Define the parameters with initial values and units
param1={0, 'unit'}; %unit should be replaced with the actual units of param1
param2 = {0, 'unit'};
% Add more parameters as needed
end
function setup
% Loading the parameters from the external .m file
% Ensure the .m file is on the MATLAB path
params = feval('valveParams', valveType);
% valveParams is the separated .m file which contains a function that returns the structure of parameters based on the valve type.
% valveType is the type of the valve selected from the dropdown.
% Assign the loaded parameters to the component parameters
param1 = params.param1;
param2 = params.param2;
% Assign more parameters as needed
end
By following this method, parameters can be loaded dynamically to the simscape component based on the selected valve type.
For more information regarding the “feval” function kindly refer the following documentation https://www.mathworks.com/help/matlab/ref/feval.html
I hope this helps.
  1 commentaire
Moritz
Moritz le 6 Août 2024 à 9:00
Modifié(e) : Moritz le 7 Août 2024 à 13:52
Thanks! This is, what I was looking for and it works! :)
However, I get the following warning,
Warning: File: Line: 1, the unit of value assigned to 'param1' was changed from '1' to 'Pa'.
when I use this setting.
parameters
param1 = {0, 'Pa'};
end
function setup
params = feval('valveParams', valveType);
param1 = params.param1;
end
I can suppress the warning, by adding the 'unit' in the 'function setup',
parameters
param1={0, 'Pa'};
end
function setup
params = feval('valveParams', valveType);
param1 = {params.param1, 'Pa'};
end
To me, this seems to be redundant. Is this correct or can I solve this differently?
Matlab states that using the setup function is not recommended ((Not recommended) Prepare component for simulation - MATLAB - MathWorks Benelux). Would it be possible to do the same things without using the setup function? I am just curious.
Thanks!

Connectez-vous pour commenter.

Catégories

En savoir plus sur Foundation and Custom Domains dans Help Center et File Exchange

Produits


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by