How to delete 'Userdata' in hObject of Matlab GUI?

조회 수: 8 (최근 30일)
Tyann Hardyn
Tyann Hardyn 2022년 1월 1일
댓글: Tyann Hardyn 2022년 1월 1일
Dear, Community
I need to remove some 'Userdata' (handles.noise, 'Userdata') from a callback function (Gui Pushbutton) before processing the data. I create a code for it in this function :
% --- Executes on button press in loadplot.
function loadplot_Callback(hObject, eventdata, handles)
% hObject handle to loadplot (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
cek_interp_yet = sum(isempty(get(handles.grafik, 'Userdata')));
cek_nois_yet = sum(isempty(get(handles.noise, 'Userdata')));
data_interp = get(handles.grafik, 'Userdata');
data_noise = get(handles.noise, 'Userdata');
if cek_nois_yet == 0
data_noise = [];
clear data_noise;
end
if cek_interp_yet == 0
data_interp = [];
clear data_interp;
end
Stuffs...........
After pushing the button, and when i click another radiobutton in response to the "(handles.noise, 'Userdata')", it evidently still showing the same 'Userdata' as if it was not deleted yet.
^ The above picture is a screenshot from a function of createfcn radio button when it process to plot a graph right after clicking on it. Because of this, the variable of cek_nois_comp is still 0 which mean the data (1440 x 22) string array was still not deleted yet (i want to make the variable of cek_nois_comp to become 1) so then the proceed can be resumed.....
So, anyone, would you like to help me out from this problem? Thank you so much /.\ /.\ /.\

채택된 답변

Voss
Voss 2022년 1월 1일
Using clear just clears the local variables in the callback function. You should do:
set(handles.grafik, 'Userdata', []);
set(handles.noise, 'Userdata', []);
  댓글 수: 1
Tyann Hardyn
Tyann Hardyn 2022년 1월 1일
Reasonable and It WORKS ! Thats why i cant delete it just by using clear or [ ] ......
Thank you so much, Sir !

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

추가 답변 (2개)

Chunru
Chunru 2022년 1월 1일
How about this?
handles.grafik.Userdata=[];
handles.noise.Userdata=[];
...
  댓글 수: 1
Tyann Hardyn
Tyann Hardyn 2022년 1월 1일
Yeah, this works also, Sir Chunru, thank you so much !!

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


Image Analyst
Image Analyst 2022년 1월 1일
To remove a field (that's not a UI control) from handles (like it's a field you manually added at some point), you can use rmfield():
handles = rmfield(handles, 'noise');
% Now you will need to call guidata() or else once you exit the function noise will still be there because you
% removed it from only a local copy of handles.
% Update handles structure
guidata(hObject, handles);
Note that you need to call guidata() if you make changes to handles that you made manually. For changes to widgets on the GUI (buttons, text, listboxes, etc.), you don't need to call guidata.
If you want to keep the field but just get rid of the value you can set the field to null:
handles.noise = [];
Note: you do this to handles, not to hObject like you stated in you subject line.

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by