Making class accessible without having its .m file in current folder
1 view (last 30 days)
Show older comments
Grzegorz Diaczek
on 17 Nov 2022
Commented: Grzegorz Diaczek
on 17 Nov 2022
MATLAB classdef has been created. I would like to create new objects of this class and share them with other users. It is possible to sent them a .m file with classdef and place it in the special MATLAB folder, that it will be accessible without having the .m file in current folder? I want to let them just open the MATLAB, drag and drop prepared object saved in .mat file to workspace and work on it without selecting the folder where the .m file is defined. Thanks for help.
0 Comments
Accepted Answer
Steven Lord
on 17 Nov 2022
In order to create or work with an instance of the class, it must be accessible to MATLAB. This means it must be in the "current scope", which this documentation page defines as "the current file, an optional private subfolder relative to the currently running function, the current folder, and the MATLAB path."
Class definitions can't be in private folders (see the "No Class Definitions in Private Folders" section on this documentation page) so if you want to be able to call it but not have it be in the current folder it will need to be on the MATLAB search path.
One useful place to put the downloaded class definition would be in their userpath directory which is part of the search path by default.
More Answers (0)
See Also
Categories
Find more on Software Development Tools in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!