필터 지우기
필터 지우기

Problems with which function in 2021a vs 2016b

조회 수: 2 (최근 30일)
Abdul Moiz Fazlani
Abdul Moiz Fazlani 2022년 3월 28일
답변: Prasanna Konyala 2022년 4월 1일
Hi,
I am having trouble getting file path of get methods using "which" function in 2021a. I don't encounter this problem in 2016b.
For example, I have a classX which has a method get.something:
  1. In 2016b : which('classX>get.Something') gives the full path of where classX is located.
  2. However in 2021a : which('classX>get.Something') says that get.Something not found.
I have tried many things but not been able to make it work. I am a relatively new to matlab so any help will be appreciated.
  댓글 수: 2
Walter Roberson
Walter Roberson 2022년 3월 28일
Are you taking into account that using which() to inquire about methods of a class generally does not work until at least one object has been constructed from the class?
Abdul Moiz Fazlani
Abdul Moiz Fazlani 2022년 3월 28일
Yes. I am only facing this problem with get and set methods. All other methods working fine with "which" function. For example: which('classX>Something') works fine

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

채택된 답변

Prasanna Konyala
Prasanna Konyala 2022년 4월 1일
Hi
MATLAB calls get and set methods when any code accesses the properties.
Property access methods do not appear in the list of class methods returned by the methods command and are not accessible through which command. These are also not included in the meta.class object Methods property. This is documented behavior. If you want to get path, you can use function handles for getters and setters.
mc = ?ClassName;
mp = findobj(mc.PropertyList,'Name',PropertyName);
fh = mp.GetMethod;
fh is function handle for the get method and it can help you locate the code

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Construct and Work with Object Arrays에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by