I have some Simulink models, MATLAB functions and scripts. How can I create a Simulink Project and include all the existing files?
MATLAB: How to create a Simulink Project from existing files
simulink
Related Solutions
The project can store its data using in a fixed path length format that solves this issue.
To change the project definition file format for an existing project:
- Go to MATLAB's preference dialog
- Select the project preferences and set "Project definition files:" to "use multiple project files (fixed path length)"
All new projects should now use this format. To convert an existing project to use this format.
- Set the preferences as described above
- Export the project to a project archive. In the project toolstrip tab: select "Share->archive"
- Double click on the newly created .MLPROJ file. This will create a new instance of the project using the fixed path data format
If your existing project is under source control in Git, there are a few extra steps.
- Set the preferences as described above
- Export the project via the "Share -> archive" menu. MATLAB automatically converts the metadata folder to a "resources" folder, and all paths, shortcuts, etc are saved in this process
- Open the exported Project in MATLAB
- Copy the metadata folder in the exported project. Prior to R2019a, projects' metadata folders may have been in either ".SimulinkProject", or "_SimulinkProject". In new releases, the recommendation is to use "resources" as the project metadata folder which is the default in R2019a and newer.
- Delete the metadata folder in the original Project in Git. This folder is either "resources", ".SimulinkProject", or "_SimulinkProject"
- Add the new metadata folder ("resources" and all subfolders/files) to Git in the original Project
- Commit changes to Git
- Create the project.
- Create a command line project, for example “EngineDemo”. From the menu of Xcode, select File -> New -> Project. After the new window pops up, choose “Command Line Tool” from Application under OS X category. In following steps, choose C++ as the Language and fill “EngineDemo” as Product Name.
- Delete the automatic generated C++ file. Right click on the generated file “main.cpp” under folder “EngineDemo” in the Project navigator view and select “Delete”.
- Add the Engine example file to the project. Right click on the folder “EngineDemo” under “EngineDemo” project in Project navigator view, choose “Add Files to EngineDemo” and then select the file “engdemo.cpp” from “<matlabroot>/extern/examples/eng_mat/” folder. “<matlabroot>” represents where the folder MATLAB is installed, for example, “/Applications/MATLAB_R2015a.app”.
- Configure the Build settings.
- Click on the project “EngineDemo” from the Project navigator view.
- Add linker flags. Choose Build Settings -> Linking -> Other Linker Flags. Add “-leng –lmx” to the debug build.
- Add header paths. Choose Build Settings -> Search Paths -> Header Search Paths, add “<matlabroot>/extern/include” to the debug build.
- Add library search paths. Choose Build Settings -> Search Paths -> Library Search Paths, add “<matlabroot>/bin/maci64” to the debug build.
- Configure environment variables for debugging.
- From the menu of Xcode, select Product -> Scheme -> Edit Scheme.
- After the new window pops up, select Run/Debug from the left panel and choose “Debug” from Build Configuration in the Info panel.
- Select Arguments from the right panel and add following environment variables in the Environment Variables section: DYLD_LIBRARY_PATH with value “<matlabroot>/bin/maci64”, and PATH with value “<matlabroot>/bin:$PATH”.
- Build and run the Engine application “EngineDemo”.
Best Answer