How to clear variable from GUI?

조회 수: 13 (최근 30일)
Ibro Tutic
Ibro Tutic 2017년 6월 16일
댓글: Adam 2017년 6월 16일
I am plotting from a structure called handles.data. I have a push button to clear all graphs and this structure to plot other things, but the clear command doesn't seem to be working. When I try to replot using the same code as before, I get an error saying "Subscripted assignment between dissimilar structures." When I check handles.data, I have a struct with no fields. How would I just remove the variable completely?
try
for i=1:length(handles.graphs)
close(i)
end
clear handles.name
clear handles.data
catch ME
clear handles.name
clear handles.data
handles.j=1;
end
guidata(hObject, handles);

답변 (1개)

Adam
Adam 2017년 6월 16일
편집: Adam 2017년 6월 16일
handles.data = [];
will reset the field to empty (which is what I usually do because I use an isempty(...) test when using the data)
handles = rmfield( handles, 'data' );
would remove the field.
clear is used for clearing variables, you can't clear a field of a structure with it.
clear handles
would be valid syntax, but do not do this in a GUI as it will remove the whole structure and make your GUI unusable.
  댓글 수: 2
Ibro Tutic
Ibro Tutic 2017년 6월 16일
So I attempt to clear the structure by doing
handles.data=[];
When I try to plot again, I get the error "Conversion from double to struct not possible". The structure handles.data is contains a nested structure (handles.data.Plot.data). Does this matter?
Adam
Adam 2017년 6월 16일
Well, after
handles.data = [];
it doesn't contain anything, which was the point, as far as I could tell from your question.
You have posted any plotting code so I have no idea what that does, but if you are trying to plot what is in handles.data then I would assume you have run some code which populates it again after clearing it.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by