How to check for a custom property in a table
조회 수: 14 (최근 30일)
이전 댓글 표시
Hi,
is there an easy way to check if a Custom Property in a table has been set, i.e. if it exists?
I know I can pass a structure to UserData in a table with a series of fields and then use isfield to check if a field exists. I cannot find a similar way to check for properties. There is a command isprop but it either doesn't work for this or I am using it wrong. Also T.Properties.Customproperties is not a structure on which isfield can operate, even thought it uses the dot operator.
Here is a MWE
t = array2table(rand(10,3));
t = addprop(t,'LineWidth','variable');
t.Properties.CustomProperties
I want to check if LineWidth or DisplayName exist. One should give me 1, the other 0.
Thanks!
댓글 수: 0
답변 (3개)
Voss
2022년 6월 17일
편집: Voss
2022년 6월 17일
isprop should work:
t = array2table(rand(10,3));
isprop(t.Properties.CustomProperties,'LineWidth')
isprop(t.Properties.CustomProperties,'DisplayName')
isprop(t,'LineWidth')
isprop(t,'DisplayName')
% add LineWidth property
t = addprop(t,'LineWidth','variable');
isprop(t.Properties.CustomProperties,'LineWidth')
isprop(t.Properties.CustomProperties,'DisplayName')
isprop(t,'LineWidth')
isprop(t,'DisplayName')
댓글 수: 2
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!