Locate MATLAB Class Definition File

15 views (last 30 days)
DBFun
DBFun on 13 Oct 2022
Commented: DBFun on 13 Oct 2022
I've recently inherited responsibility for a MATLAB app that was built by an individual who is no longer with my company. The code for the app is organized into multiple layers of nested folders and package folders that contain various class definition files.
Rather than making full use of a package folder structure with appropriate import statements in the code, the app adds most of the folders to the MATLAB path with "addpath". That wouldn't normally be the end of the world, but in this case there are multiple package folders and class definition files with identical names that all wind up getting added to the path at various points in the code. This is causing some difficult to diagnose problems.
To help troubleshoot the issues, I would like a function that takes a single input argument in the form of an object and returns a string containing the file path to the class definition for that object. I know that MATLAB has the "which" command that does basically this exact thing for functions, but I haven't been able to figure out how to do it for an object. Any thoughts?

Accepted Answer

Fangjun Jiang
Fangjun Jiang on 13 Oct 2022
'datetime' is a MATLAB class.
a=datetime
a = datetime
13-Oct-2022 18:50:58
which datetime
/MATLAB/toolbox/matlab/datatypes/datetime/@datetime/datetime.m % datetime constructor
  2 Comments
DBFun
DBFun on 13 Oct 2022
I must have something else going on. When I try that with one of the app's objects, the properties defined in the file returned by "which" do not match the properties of the object I'm looking at.
DBFun
DBFun on 13 Oct 2022
Nevermind - I got it. I was reading the file path returned by "which" wrong...oops. Thanks for your help.

Sign in to comment.

More Answers (0)

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!