Add folder and subfolder to project path
Hi everyone,
I’m trying to use the addPath function to add multiple folders to a MATLAB project’s path. According to the documentation, the folders input argument should be:
"Path of the folders to add to the project path, specified as string array or as a cell array of character vectors. The folders must be within the root folder."
Here’s a minimal example of what I tried:
tmp = ["Hello", "HelloWorld"];
addPath(proj, tmp);
but I got this error:
Error using matlab.internal.project.japi.Project/addPath
Expected file to be of size 1×1, but it is of size 2×1.
Error in matlab.project.Project/addPath
Even though tmp is a string array, MATLAB seems to expect only a single path.
For context:
The folders already exist within the project
I’ve added them (and their subfolders/files) using addFolderIncludingChildFiles, but that function doesn’t add the folders to the project path
I’m using MATLAB R2024b
I’m trying to use addPath with multiple folders at once because adding each folder path in a for loop is very time-consuming when dealing with many subdirectories.
Has anyone managed to add multiple folders at once using addPath, or is it necessary to call it one folder at a time?
Any suggestions or workarounds would be greatly appreciated!
Thanks in advance!Hi everyone,
I’m trying to use the addPath function to add multiple folders to a MATLAB project’s path. According to the documentation, the folders input argument should be:
"Path of the folders to add to the project path, specified as string array or as a cell array of character vectors. The folders must be within the root folder."
Here’s a minimal example of what I tried:
tmp = ["Hello", "HelloWorld"];
addPath(proj, tmp);
but I got this error:
Error using matlab.internal.project.japi.Project/addPath
Expected file to be of size 1×1, but it is of size 2×1.
Error in matlab.project.Project/addPath
Even though tmp is a string array, MATLAB seems to expect only a single path.
For context:
The folders already exist within the project
I’ve added them (and their subfolders/files) using addFolderIncludingChildFiles, but that function doesn’t add the folders to the project path
I’m using MATLAB R2024b
I’m trying to use addPath with multiple folders at once because adding each folder path in a for loop is very time-consuming when dealing with many subdirectories.
Has anyone managed to add multiple folders at once using addPath, or is it necessary to call it one folder at a time?
Any suggestions or workarounds would be greatly appreciated!
Thanks in advance! Hi everyone,
I’m trying to use the addPath function to add multiple folders to a MATLAB project’s path. According to the documentation, the folders input argument should be:
"Path of the folders to add to the project path, specified as string array or as a cell array of character vectors. The folders must be within the root folder."
Here’s a minimal example of what I tried:
tmp = ["Hello", "HelloWorld"];
addPath(proj, tmp);
but I got this error:
Error using matlab.internal.project.japi.Project/addPath
Expected file to be of size 1×1, but it is of size 2×1.
Error in matlab.project.Project/addPath
Even though tmp is a string array, MATLAB seems to expect only a single path.
For context:
The folders already exist within the project
I’ve added them (and their subfolders/files) using addFolderIncludingChildFiles, but that function doesn’t add the folders to the project path
I’m using MATLAB R2024b
I’m trying to use addPath with multiple folders at once because adding each folder path in a for loop is very time-consuming when dealing with many subdirectories.
Has anyone managed to add multiple folders at once using addPath, or is it necessary to call it one folder at a time?
Any suggestions or workarounds would be greatly appreciated!
Thanks in advance! matlab, iteration, vectorization, optimization MATLAB Answers — New Questions









