我需要在弹出菜单中选择的轴上显示图像。 我使用以下代码动态生成弹出菜单列表:
function popupmenu1_Callback(hObject,eventdata,handles)
DirEntries = dir(' C:\ Users \ User \ Desktop \ Project \ Images'); uicontrol(' Style',' popup',' String',{DirEntries.name});
现在,我在此弹出式菜单中选择的任何图像都应显示在'轴中
任何人都可以帮我了解如何在GUI中显示所选图像
答案 0 :(得分:0)
此代码应该完成工作
function script
figure;
directory = 'C:\Users\User\Desktop\Project\Images';
Dir = dir(directory);
axes;
h = uicontrol('Style','popup', 'String', {Dir.name}, 'Callback', @popupmenu1_Callback);
setappdata(h,'Dir', directory);
function popupmenu1_Callback(hObject, eventdata, handles)
value = get(hObject, 'Value');
directory = getappdata(hObject, 'Dir');
images = get(hObject, 'String');
% Do a check if this is a valid image
imshow(strcat(directory,'/', images{value}));