Making class accessible without having its .m file in current folder

4 次查看(过去 30 天)
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.

采纳的回答

Steven Lord
Steven Lord 2022-11-17
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Software Development Tools 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by