Error when creating a custom library in Simscape. Class definition question

13 次查看(过去 30 天)
Hi, I would be really pleased if you can help me with a question I have regarding constructing custom components in Simscape. I am developing an alkaline cell and the electrochemical model is based on its majority in empirical equations. However, it could be the case that the user knows the value of specific parameters such as exchange current density, charge transfer coefficients for electrodes, electrodes conductivity, etc. Because of this, I would like to give the user the possibility of choosing (when selecting the component from the library) between the option of writing the value of those parameters or selecting instead an option called "equation" and in that case the equations defined in the component .ssc file are run inside the component. I created .m files for each desired parameter with its classdef < Simulink.IntEnumType and stored them in a folder (+Enums) and called them in the .ssc file of my component with he folder path. However, when creating the library an error appears stating that the first name of the folder in the folder path is "not defined in this scope".
For example, I want to define the class definition for the parameter anode conductivity. 1) .m file with the class definition: conductivity_an.m
classdef conductivity_an < Simulink.IntEnumType
enumeration
equation (1)
parameter (2)
end
end
2) In my custom component code:
parameters
conductivity_an = AEL.Enums.conductivity_an.equation; % Anode electrical conductivity specification
% 1 - equation
% 2 - parameter
end
parameters (ExternalAccess = none)
sigma_an_g = {11808768, 'S/m'}; % Anode electrical conductivity given by user
end
if conductivity_an == AEL.Enums.conductivity_an.equation
intermediates (ExternalAccess = none)
sigma_an = 6000000 -279650*(T_stack) + 532*(T_stack^2) + 0.38057*(T_stack^3);
end
else
annotations
sigma_an_g : ExternalAccess = modify;
end
parameters (Access = private)
sigma_an = sigma_an_g;
end
equations
assert(sigma_an_g > 0)
end
end
What might be the issue? Is it feasible to develop a class description that can accomplish my goals?
Thank you very much!

采纳的回答

Sameer
Sameer 2025-8-4,10:13
The issue you're seeing comes from trying to use package-style paths like "AEL.Enums" inside a ".ssc" Simscape component.
Here's how to fix it:
  1. Move the enum file "conductivity_an.m" out of the package folder (remove the "+AEL/+Enums" structure).
  2. Place it in a regular folder that's on the MATLAB path.
  3. Update your ".ssc" file like this:
parameters
conductivity_an = conductivity_an.equation;
end
No need to use the "AEL.Enums." prefix — just "conductivity_an".
Hope this helps!

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Foundation and Custom Domains 的更多信息

产品


版本

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by