how to addpath of +folder
이전 댓글 표시
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
Adam
2014년 10월 9일
Solve it in what way? You only need the parent folder on your path for package folders.
Brian C Coe
2015년 2월 18일
편집: Brian C Coe
2015년 2월 18일
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
2015년 7월 30일
MATLAB sees these functions as myfolder.my_file (taking your example).
답변 (6개)
Steve
2018년 9월 5일
4 개 추천
You have to use the syntax folder.mfile(vars), where "folder" is the folder name with the "+" before it and "mfile" is the function.
Al in St. Louis
2017년 11월 2일
3 개 추천
None of these answers actually helps.
댓글 수: 6
Steven Lord
2017년 11월 2일
You cannot add a package directory (one whose name starts with the + symbol) or a class directory (one whose name starts with the @ symbol) to the MATLAB path. It's just not allowed.
To use a program file inside a package directory, you will need to include the name of the package directory (without the +) or import the package. For instance if you had a file c:\temp\+mypackage\myfunction.m you would need to call it as mypackage.myfunction (assuming c:\temp was your current directory or was on the MATLAB path) or you would need to import mypackage before using it.
Mugetsu
2019년 1월 24일
Thank you so much for this explanation! I am a new matlab learner and didn't know how to work with classdef functions before. I found an API package developed by someone which have many subfolders inside, and I couldn't find on web how to call the sub class functions anywhere. Your answer became my medicine thanks again !
Al in St. Louis
2019년 1월 24일
I agree with Mugetsu. Steven Lord's comment is the best "answer" on this page.
Adam
2019년 1월 25일
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
2020년 2월 29일
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.
Syed Mubashir Azeem Bukhari
2021년 5월 17일
this seems logical, can you give an example please?
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
Brian C Coe
2015년 2월 18일
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
2015년 2월 19일
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.
YIN JEH NGUI
2016년 6월 11일
0 개 추천
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
Adam
2016년 6월 13일
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.
Muhammad Usman Saleem
2016년 6월 11일
use
pwd('your directory path')
Hyunuk Ha
2021년 7월 13일
0 개 추천
You should 'import' package directory, not 'addpath'.
So, basically you may use pkg dir. as
>> mypkg.myfile(in)
but after import pkg dir.
>> import mypkg
then, you can use,
>> myfile(in)
package directory can't be add to the path, but you can import it.
Please refer to :
https://www.mathworks.com/help/matlab/ref/import.html?searchHighlight=import&s_tid=doc_srchtitle
댓글 수: 1
Hyunuk Ha
2021년 7월 13일
You may know (explicitly) imported pkg dir. has high priority than other public methods or built-in fcn.
https://www.mathworks.com/help/matlab/matlab_prog/function-precedence-order.html
카테고리
도움말 센터 및 File Exchange에서 Search Path에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!