Hi all, I'm learning to use the Simscape environment and create custom libraries. I've run into an error trying to create a package with subdirectories. Using the THyd example from https://www.mathworks.com/help/simscape/lang/working-with-domain-parameters.html, my folders are structured as follows with my Documents\MATLAB folder which I've added with addpath:
- +TestModels
|-- +THyd
| |-- t_hyd.ssc
| |-- hyd_temp.ssc
| |-- h_temp_sensor.ssc
| |-- h_temp_ref.ssc
however when I try to run ssc_build TestModels I'm met with the following error:
Error using ssc_build
Failed to generate 'TestModels_lib'
Caused by:
Simscape file with package path 'THyd.t_hyd' is not on MATLAB path and not in import context declared by import statements. Ensure
the Simscape file is on MATLAB path or in import context. If theSimscape file is moved or renamed, use its new package path.
• In TestModels.THyd.h_temp_ref (line 5)
where line 5 is the a = THyd.t_hyd node declaration. Removing +THyd from +TestModels and running ssc_build THyd works without issue. I can't seem to find record of this error anywhere else. Any thoughts on how to resolve the issue? I will be using the TestModels folder for future projects, so while just using THyd is fine for now I'm looking for a solution that allows subdirectories.

 채택된 답변

Christopher
Christopher 2023년 6월 9일

0 개 추천

In spending a few more hours of trial and error I answered my own question, so here we go. The answer, as is often the case, is right in the error message. I was trying to declare an instance of THyd.t_hyd, when the actual path was TestModels.THyd.t_hyd. Creating a +package requires it be specified in the domain path, so that was my issue.
I actually realized this after working around the issue by creating a separate Simulink library and creating a subsystem within it as per https://www.mathworks.com/help/simulink/ug/adding-libraries-to-the-library-browser.html, so if you're experiencing the same or a similar error and the first method doesn't correct it, the attached link should do the trick. Happy coding!

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Foundation and Custom Domains에 대해 자세히 알아보기

제품

릴리스

R2023a

질문:

2023년 6월 9일

답변:

2023년 6월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by