How to check for a custom property in a table
10 次查看(过去 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')
另请参阅
类别
在 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!