how to clear all the variables in the GUI every time when we run it?

3 views (last 30 days)
Hi,
I have a GUI in which I'll load an image and do some analysis to it. But, when I load the next image to do analysis in the same GUI, I want to clear all the variables.
I used "clear all" in the callback of push button where I'll load the image.
But, I am facing error as
Reference to a cleared variable handles.
Error in Immunostaining_GUI>load_image_Callback (line 110)
set(handles.text1,'string',details);
Any suggestions please.
Thanks...

Answers (1)

Image Analyst
Image Analyst on 3 Feb 2015
You don't want to do that! Doing that will blow away the handles structure which is essential for running your GUIDE-built GUI. When you click some button, say Go!, to start off your image processing, it will run the callback for the Go! button and when it enters that callback, there will be no variables existing except the handles structure. So there is nothing to clear - no need to. You have to create all variables that you will need and use, for example by using global, getappdata, the handles fields, reading mat files, reading workbooks, reading image files with imread(), calling zeros() or ones() or rand(), etc., or by simple assignment
  2 Comments
Manoj Kumar
Manoj Kumar on 3 Feb 2015
Actually I am not closing and opening the GUI to load another image. Without closing it i need to load another image. The reason to clear the past variables is because some variables are not needed when I load another image.
Image Analyst
Image Analyst on 3 Feb 2015
I know you're not, but you're still entering a callback function to do your operations. And that callback function has a completely new workspace - clean slate with no variables in it except handles. Why do you think the variables are still in existence???

Sign in to comment.

Categories

Find more on Images in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!