How to check for a custom property in a table
8 ビュー (過去 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 で Function Creation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!