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

1 次查看(过去 30 天)
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!

回答(3 个)

Jan
Jan 2012-12-3
编辑:Jan 2012-12-3
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 个评论
Dani Tormo
Dani Tormo 2012-12-4
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 2017-2-16
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!

请先登录,再进行评论。


Walter Roberson
Walter Roberson 2012-12-3
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 个评论
Dani Tormo
Dani Tormo 2012-12-3
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 2012-12-3
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)

请先登录,再进行评论。


Dani Tormo
Dani Tormo 2012-12-10
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!

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by