display and image when specefic checkbox is selected

4 views (last 30 days)
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')

Accepted Answer

Walter Roberson
Walter Roberson on 8 Nov 2016
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')

More Answers (0)

Community Treasure Hunt

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

Start Hunting!