Matlab GUI - 将弹出菜单中选择的图像显示到轴

Matlab GUI - Display image selected in popupmenu to axes

我需要在弹出菜单中 select 编辑的坐标轴中显示图像。 我正在使用以下代码动态生成弹出菜单列表:

函数popupmenu1_Callback(hObject, eventdata, handles)

DirEntries = dir('C:\Users\User\Desktop\Project\Images'); uicontrol('Style','popup','String',{DirEntries.name});

现在我 select 在这个弹出菜单中的哪个图像应该显示在 'axes'

任何人都可以帮助我如何在 GUI

中显示 selected 图像

这段代码应该可以完成工作

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}));