How to clear GUI variables?

조회 수: 11 (최근 30일)
Kev
Kev 2013년 12월 17일
편집: Kev 2013년 12월 18일
Hi,
I'm trying to clear GUI variables. From what I understand, each callback function has its own workspace and separate global workspace. I'd like to clear a specific callback variables with a push button. (Callback function is blockremover_callback, I'd like to reset with a push button).
Thanks!
function clearscreen_Callback(hObject, eventdata, handles)
global xy h binary
%evalin('base','clear h')
clear blockremover_callback
xy = [];
h = [];
binary = [];
%evalin('base','clear all');
cla;

채택된 답변

Image Analyst
Image Analyst 2013년 12월 18일
You can clear global variables with clear global.
clear global xy;
clear global h;
clear global binary;
After you clear them, if you need them you need to declare them again:
global xy;
global h;
global binary;
There is no need to clear local variables as they vanish once the function exits.
  댓글 수: 3
Image Analyst
Image Analyst 2013년 12월 18일
Like I said in your other question, if it thinks there is more than one image in an axes, then call cla('reset') before calling imshow() so that the axes is emptied before loading an image into it.
Kev
Kev 2013년 12월 18일
편집: Kev 2013년 12월 18일
Perfect! Wish thre were emoticons on this forum. :) The problem was with resetting axis. I thought it was something else. I applied cla command in the block. I didn't know there were separate cla('reset') function also. Anyways, Thanks very much!!!

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2013년 12월 17일
No, there is only one global workspace.
Each function may have its own persistent variables. Those variables may be cleared by using "clear" together with the function name.
  댓글 수: 1
Kev
Kev 2013년 12월 18일
편집: Kev 2013년 12월 18일
Thanks for providing link. That wiki is informative. Bookmarked! :)

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by