MATLAB Answers

how to addpath of +folder

224 views (last 30 days)
nt
nt on 9 Oct 2014
Commented: Ralph on 29 Feb 2020
when I add path like
addpath('C:\+myfolder')
it shows
Warning: Package directories not allowed in MATLAB path:
Can I know how to solve it?

  3 Comments

Adam
Adam on 9 Oct 2014
Solve it in what way? You only need the parent folder on your path for package folders.
Brian C Coe
Brian C Coe on 18 Feb 2015
when i try to open, edit, or find help for a file in one of these needlessly hidden folders matlab says it can't find it... despite the fact that the parent folder has been added to the path.
>> edit my_file
Error using edit (line 61)
Neither 'my_file' nor 'my_file.m' could be
found.
Thierry Dalon
Thierry Dalon on 30 Jul 2015
MATLAB sees these functions as myfolder.my_file (taking your example).

Sign in to comment.

Answers (5)

Steve
Steve on 5 Sep 2018
You have to use the syntax folder.mfile(vars), where "folder" is the folder name with the "+" before it and "mfile" is the function.

  0 Comments

Sign in to comment.


SK
SK on 9 Oct 2014
Edited: SK on 9 Oct 2014
Matlab does not allow you to add class directories or package directories individually to the path.
You have to add the parent directory instead and the class/package directory then gets automatically added.

  2 Comments

Brian C Coe
Brian C Coe on 18 Feb 2015
um, no it doesn't get automatically added.
i say that because when i try to open, edit, or find help for a file in one of these needlessly hidden folders matlab says it can't find it... despite the fact that the parent folder has been added to the path.
>> edit my_file
Error using edit (line 61)
Neither 'my_file' nor 'my_file.m' could be
found.
Adam
Adam on 19 Feb 2015
Trying to edit a file from command line is a different action from Matlab being able to find the code to run the functions.
Having a package parent folder added to the path allows the latter, but for the former you will likely have to give a full path or path relative to your working directory because the package folders are not themselves on the path.

Sign in to comment.


YIN JEH NGUI
YIN JEH NGUI on 11 Jun 2016
This is due to "+" symbol in your folder name. Change it and you can add it. I faced the same issue and can only ammend the folder name for addpath to work. Bugs maybe?

  1 Comment

Adam
Adam on 13 Jun 2016
The + defines that the folder is a package. Without it the folder is no longer a package so getting rid of it will not be helpful at all.

Sign in to comment.


Muhammad Usman  Saleem
Muhammad Usman Saleem on 11 Jun 2016
use
pwd('your directory path')

  0 Comments

Sign in to comment.


Al in St. Louis
Al in St. Louis on 2 Nov 2017
None of these answers actually helps.

  5 Comments

Show 2 older comments
Al in St. Louis
Al in St. Louis on 24 Jan 2019
I agree with Mugetsu. Steven Lord's comment is the best "answer" on this page.
Adam
Adam on 25 Jan 2019
It is a shame though that the import syntax works only within function scope. As an object-oriented programmer I would regularly like to be able to import a package once into my whole class to avoid having to keep giving the package name. Without this I pretty much never use the import option as I often just refer to a package object once or twice within a function, but in numerous different functions of a single class.
Ralph
Ralph on 29 Feb 2020
The critical issue is twofold:
(1) The '+' indicator means it is a package folder
(2) packages in Matlab are a broken cludge
Functions within a package can not call one another unless every single one of them features the import function. And that import must have the name of the package. So you can't just put a bunch of related files in a package and be done. You have to go through every file and add the import command. Which is to say - packages in Matlab are a broken cludge.

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by