필터 지우기
필터 지우기

Looping through properties of a class object

조회 수: 66 (최근 30일)
Giri
Giri 2018년 3월 13일
댓글: Greg 2018년 3월 15일
Hi,
I am developing a code to create an XML file from the data retrieved from an excel sheet. The retrieved data are stored in a class object(objClsScene for example which is an object of clsScene). clsScene has properties like description (string), name (string) , rate (integer) etc. It also has objects of other classes as its properties ( for example: objCls1, objCls2, objCls3 etc).
Is there any way by which i can iterate or loop through the properties of objClsScene so that i may extract the data stored in objCls1, objCls2 etc depending on my requirements. Or are there any other method by which i may attain the same result?
I am new to matlab coding and any thoughts on this would be really appreciated.
Thanks in advance.

채택된 답변

Greg
Greg 2018년 3월 14일
props = properties(objClsScene);
for iprop = 1:length(props)
thisprop = props{iprop};
%%%Add logic here if you want to work with select properties
thisprop_value = objClsScene.(thisprop);
%%%Add logic here if you want to do something based on the property's value
end
  댓글 수: 2
Giri
Giri 2018년 3월 15일
Thanks a lot Greg. This snippet is exactly what i wanted. Thanks a lot!!!
Greg
Greg 2018년 3월 15일
Happy to help.

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by