Tag of one of the axes erased after reopening GUIDE project.

1 view (last 30 days)
Hello,
I have a problem and I don't know where it comes from.
I have a GUI with four axes. One of these I use it to show a PNG image on the create function:
function circuit_CreateFcn(hObject, eventdata, handles)
imatge=imread('altres\base circuit reduit.png');
image(imatge);
axis off;
The problem is that every time I close Matlab and open the GUI again, the Tag of the axes (circuit) is empty.
Why is happening this?
Thanks!

Answers (3)

Jan
Jan on 3 Dec 2012
Edited: Jan on 3 Dec 2012
Does the image() command clear the tag?
axesH = gca; % Not safe! Better get the handle explicitly!
imatge = imread('altres\base circuit reduit.png');
disp(get(axesH, 'Tag'));
image(imatge);
disp(get(axesH, 'Tag'));
axis off;
If so, set the 'NextPlot' property of the axes object to "add" instead of "replace" before calling image(). Or store the tag and restore it afterwards:
bakTag = get(axesH, 'Tag');
image(imatge);
set(axesH, 'Tag', bakTag);
I cannot test this currently. Clearing the axes' properties happens for other high-level functions as imshow and plot, but not for low-level functions as line.
  2 Comments
Dani Tormo
Dani Tormo on 4 Dec 2012
Setting the NextPlot to add didn't work. I only set this image once at the program start.
I don't really know what's going on. Today I opened the GUI and there were no tag but I run the GUI and the image was shown. Then I put the tag correctly and the image is not shown anymore until I click on the axes to open the callback CreateFcn. Then It charges the image correctly again.
I don't know why but the Tag is erased every time I close the GUI. When I am working on it everything works fine.
Thanks for your help!
Guy Starbuck
Guy Starbuck on 16 Feb 2017
This fixed my problem, the tag on the axes was getting stomped when I loaded it. I can't imagine why this is the default behavior. Thanks for the help as always!

Sign in to comment.


Walter Roberson
Walter Roberson on 3 Dec 2012
If you go into GUIDE and add the tag back in, and save the result, then afterwards if you load just the .fig file, is the tag still there? And does that tag persist when you run the GUI ?
That is, something in the initialization of the GUI might be clearing the axes. clearing an axes removes its tag.
  2 Comments
Dani Tormo
Dani Tormo on 3 Dec 2012
Yes, the tag stills there until I restart matlab. I tried to delete this axes and put another with different name but does the same.
Is the right place to set the image at the creation of the axes? Maybe is something wrong with that.
Walter Roberson
Walter Roberson on 3 Dec 2012
If you save the version with the tag in GUIDE, and quit MATLAB and then openfig() the .fig file, is the tag still there?
My suspicion is that something that happens before that point in the code is clearing the axes in the form you need it.
I can't really advise on whether that is a good place to set the image when using GUIDE, as I don't use GUIDE (too unpredictable for more complex work, too hard to do good dynamic layouts)

Sign in to comment.


Dani Tormo
Dani Tormo on 10 Dec 2012
I don't know what I did but now I don't have this problem anymore. Probably because I erased some callback functions of this axis that were empty and some others of the main figure.
Thanks for your answers anyway!

Categories

Find more on Specifying Target for Graphics Output in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!