display and image when specefic checkbox is selected

1 次查看(过去 30 天)
Here I have 3 functions : I have 2 checkboxes and 1 axis. I simply want to display an image 'gable.gif' when i checkbox Gable_checkbox. And when i undo, i want to get rid of the image (so that i can use an other one if i checkbox Tunnel_checkbox). I tried to use : visible "on" and "off" but seems not to work. Im stuck. Can someone help me with this pls? Thank you!
============================================================
function Tunnel_Callback(hObject, eventdata, handles)
checkboxStatus1 = get(handles.Tunnel,'Value');
if checkboxStatus1 == 1
set(handles.editS,'enable','off')
set(handles.editG,'enable','off')
set(handles.editC,'enable','on')
set(handles.Gable,'enable','off')
else
set(handles.editS,'enable','on')
set(handles.editG,'enable','on')
set(handles.Gable,'enable','on')
end
guidata(hObject,handles)
============================================================
function Gable_Callback(hObject, eventdata, handles)
checkboxStatus2 = get(handles.Gable,'Value');
if checkboxStatus2 == 1
set(handles.editC,'enable','off')
set(handles.editS,'enable','on')
set(handles.editG,'enable','on')
set(handles.Tunnel,'enable','off')
set(handles.axes3,'visible','on')
else
set(handles.editC,'enable','on')
set(handles.Tunnel,'enable','on')
set(handles.axes3,'visible','off')
end
========================================================
function axes3_CreateFcn(hObject, eventdata, handles)
imshow('Gable.gif')

采纳的回答

Walter Roberson
Walter Roberson 2016-11-8
Setting an axes to be visible or not does not change whether you can see what is drawn in the axes: axes visible or not controls whether you can see the box and tick marks and so on.
You need to find the image() object in the axes and turn it on or off. One way is to tag it just after you create it, and then search for the tag:
function axes3_CreateFcn(hObject, eventdata, handles)
h = imshow('Gable.gif', 'Parent', hObject);
set(h, 'Tag', 'GableImg');
and instead of
set(handles.axes3,'visible','on')
you would
set(findobj('Tag', GableImg'), 'Visible', 'on')

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by