Locate MATLAB Class Definition File

조회 수: 10 (최근 30일)
DBFun
DBFun 2022년 10월 13일
댓글: DBFun 2022년 10월 13일
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?

채택된 답변

Fangjun Jiang
Fangjun Jiang 2022년 10월 13일
'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
DBFun
DBFun 2022년 10월 13일
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 2022년 10월 13일
Nevermind - I got it. I was reading the file path returned by "which" wrong...oops. Thanks for your help.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Whos에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by