display and image when specefic checkbox is selected

1 回表示 (過去 30 日間)
matlabnewby
matlabnewby 2016 年 11 月 8 日
コメント済み: matlabnewby 2016 年 11 月 8 日
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')
  1 件のコメント
matlabnewby
matlabnewby 2016 年 11 月 8 日
Thank you Mr Roberson, higly appreciated!!

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by