How to change folder for "slprj" folder generation?

Dear all,
I have read the following question https://www.mathworks.com/matlabcentral/answers/535769-how-can-i-change-the-location-where-generated-simulink-files-are-placed about where the "slprj" folder is created during model update and code generation.
In the Simulink preferences we can see that the parent folder changes to the current folder each time we change the working directory (so by the simulink the parent folder is always locked to "pwd").
I wanted to change the folder for "slprj" from "pwd" to "pwd/supply" in the way that each time I change the working directory the folder for "slprj" changes also the way it does by default with "pwd".
Is there a way to do so? Using startup.m for example.
Thank you!

댓글 수: 6

I usually use MATLAB Project to organize the MATLAB/SImulink files. If your simulink model is included in the project, you can configure the simulink code generation folder by setting the project's SimulinkCodeGenFolder property.
myProj = currentProj;
myProj.SimulinkCodeGenFolder = "your code generation folder path";
Sergei
Sergei 2025년 11월 6일
편집: Sergei 2025년 11월 6일
Thank you for your answer, @Chuguang Pan!
In my understanding, this would set the folder to a fixed path, which would not change if I move the project to another directory. Am I right? What I want to do is to make the path to the folder relative to the current working directory.
Example:
Model/project directory: C:\Projects\prj1
Update the model: C:\Projects\prj1\suppy\slprj is created
Copy the model/project to the different directory: C:\Prjects\prj2
Update the model: C:\Prjects\prj2\supply\slprj is created.
I hope this is a helpful explanation
@Sergei. The SimulinkCodeGenFolder included in the project is a relative folder, it depends on the RootFolder of project. I have tested this using R2025a, and find that when I move the RootFolder of the project, the path of SimulinkCodeGenFolder is also updated.
Sergei
Sergei 2025년 11월 6일
편집: Sergei 2025년 11월 6일
Thank you, @Chuguang Pan!
This actually works well with .slxc files, but the "slprj" still gets created in the working directory.
@Sergei. For setting up the path of "slprj" folder, you have to configure the SimulinkCacheFolder of project. For instance,
myProj = openProject("your project");
mkdir("codegen");
mkdir("caches");
myProj.SimulinkCodeGenFolder = ".\codegen";
myProj.SimulinkCacheFolder = ".\caches";
@Chuguang Pan, Iam sorry for this. I overlooked something and thought the slprj is still created in the root project directory, but this actually works.
Thank you a lot for your explanations! Will you leave this solution as an answer so that I can mark it as best?

댓글을 달려면 로그인하십시오.

 채택된 답변

Chuguang Pan
Chuguang Pan 2025년 11월 8일

1 개 추천

@Sergei. For setting up the path of "slprj" folder, you have to configure the SimulinkCacheFolder of project. For instance,
myProj = openProject("your project");
mkdir("codegen"); % code generation folder in the pwd
mkdir("supply"); % simulink cache folder in the pwd
myProj.SimulinkCodeGenFolder = ".\codegen";
myProj.SimulinkCacheFolder = ".\supply";

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Schedule Model Components에 대해 자세히 알아보기

제품

릴리스

R2025a

질문:

2025년 11월 6일

댓글:

2025년 11월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by