Matlab - How to check the existence of a handle -
is there way check if handle exists or not? like: if didnt declare handle, want 0 output , else 1.
i tried ishandle,isvalid,isfield,isempty don't work on "non-existent field" receive error if didnt declare handle.. "reference non-existent field 'sp'."
if try "exist name" function works variables not handles
so:
handle.a=figure; exist handle.a;
returns 0
while
handle.a=figure; a=handle.a; exist
returns 1
but i'm looking for:
handle.a=figure; exist handle.a
ans=1
%without setting handle: exist handle.a
ans=0
i hope post understandable. thank help! klaus
let me rephrase: assigning handle field of structure. want test whether there valid handle in field, , guard against wrong: (1) there's no field, (2) it's empty, (3) it's array instead of scalar, (4) it's not handle, (5) it's not valid handle.
thus:
tf = isfield(handle,'a') && isscalar(handle.a) && ishandle(handle.a);
of course, if know of conditions can never occur, can drop respective tests.
Comments
Post a Comment