Check if object's property is empty
Mostrar comentarios más antiguos
I have an xmlcomp.Edits object that was created when performing a comparison via the command
root = slxmlcomp.compare(...)
In this case, an xmlcomp.Edits object was created (see attached file) but all properties are empty. However, I don't know how to check if the properties are empty so I can catch the error that occurs when I try to access the properties. Is there a command to use when the object's properties are empty?

14 comentarios
Rik
el 20 de Feb. de 2022
Maybe numel works as expected?
Monika Jaskolka
el 20 de Feb. de 2022
Image Analyst
el 20 de Feb. de 2022
Editada: Image Analyst
el 23 de Mzo. de 2022
What does this show
p = properties(xmlcomp)
if isfield(xmlcomp, 'Edits') && isempty(xmlcomp.Edits)
% Structure has the field but it's empty so do sommething with that knowledge.
end
Monika Jaskolka
el 20 de Feb. de 2022
Monika Jaskolka
el 20 de Feb. de 2022
Editada: Monika Jaskolka
el 21 de Feb. de 2022
per isakson
el 21 de Feb. de 2022
Monika Jaskolka
el 21 de Feb. de 2022
Editada: Monika Jaskolka
el 21 de Feb. de 2022
per isakson
el 21 de Feb. de 2022
Sorry for the noise.
Rik
el 21 de Feb. de 2022
If you don't find anything, you could also put the if in catch block. That's what I do sometimes as well. (e.g. to catch a memory error, which isn't really possible to catch in advance)
I'm confused. Could it be that 'TimeSaved' exists in root.mat and rootOP.mat, but isn't shown. I would ask @MathWorks Support Team. Anyhow, there is no property named 'missing'.
%% R2018b
OP = load("rootOP.mat");
r1 = load("root.mat");
r2 = load("root2.mat");
%%
isprop( r1.root, 'TimeSaved' )
isprop( r2.root2, 'TimeSaved' )
isprop( OP.root, 'TimeSaved' )
isprop( OP.root, 'missing' )
Henry Barth
el 23 de Mzo. de 2022
Editada: Henry Barth
el 23 de Mzo. de 2022
if you want a function for your check, you could implement it for your needs like this:
function ispropOut = SOME_FUNCTION(objIn,nameIn)
ispropOut = false(size(objIn));
for nObjRow = 1:size(objIn,1)
for nObjCol = 1:size(objIn,2)
try
objIn(nObjRow,nObjCol).(nameIn);
ispropOut(nObjRow,nObjCol) = true;
catch
end
end
end
end
Adam Danz
el 23 de Mzo. de 2022
Respuestas (1)
Fangjun Jiang
el 23 de Mzo. de 2022
Might this help?
>> EmptyRoot=xmlcomp.Edits('')
EmptyRoot =
Edits with no properties.
>> isequal(root,EmptyRoot)
ans =
logical
1
>> isequal(root2,EmptyRoot)
ans =
logical
0
Categorías
Más información sobre Construct and Work with Object Arrays en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

