How to check the existence of a variable inside handles?

7 Ansichten (letzte 30 Tage)
Vinothkumar Sethurasu
Vinothkumar Sethurasu am 10 Jun. 2021
Beantwortet: Image Analyst am 12 Jun. 2021
In GUIDE, I am creating number instances of an object & deleting some of them using the command 'delete(handles.obj.pc(index))'.
before deletion the properties are,
After excecuting deletion, the properties inside the objects got deleted. the values for the properties becomes does not exists.
Now, i am checking each created object properties to identify, the deleted objectes.
How can i check the stautus of the existance of the property vaules inside handles?

Antworten (2)

Image Analyst
Image Analyst am 12 Jun. 2021
Strange that it has fields but no values for the fields. Maybe try clear instead of delete. Or if the field obj is a variable you tacked on to handles, rather than a handle to a control on the figure, use rmfield()
handles = rmfield(handles, 'obj');
To check whether a structure has a certain field, you can use isfield():
fieldnames(handles) % List all fields to the command window so you can see what's there.
% Check if it has a field called obj
if isfield(handles, 'obj')
% It has the field called obj.
else
% It does not have a field called obj.
end
  1 Kommentar
Vinothkumar Sethurasu
Vinothkumar Sethurasu am 12 Jun. 2021
>> while using clear command getting an error -
' Error using clear
Must be a string scalar or character vector.'
>>rmfield and delete produces same results.
>>While using isfield to identify the status of existance, it returns zero (ab=0) for available fileds also.
for t=1:5
ab=isfield(handles.obj.pc(1,t),'connection_status');
if ab==1
z_con(1,t)=handles.obj.pc(1,t).connection_status;
else
z_con(1,t)=nan;
end
end
Am i missing anything in the line ' ab=isfield(handles.obj.pc(1,t),'connection_status')' ?

Melden Sie sich an, um zu kommentieren.


Image Analyst
Image Analyst am 12 Jun. 2021
Instead of
delete(handles.obj.pc(index));
try
handles.obj.pc(index) = [];

Kategorien

Mehr zu Structures finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by