How to check for a custom property in a table
12 views (last 30 days)
Show older comments
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 Comments
Answers (3)
Voss
on 17 Jun 2022
Edited: Voss
on 17 Jun 2022
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 Comments
See Also
Categories
Find more on Function Creation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!