Reputation: 337
I need to display the image in an axes which i selected in popup menu. I am generating the popup menu list dynamically by using the following code:
function popupmenu1_Callback(hObject, eventdata, handles)
DirEntries = dir('C:\Users\User\Desktop\Project\Images'); uicontrol('Style','popup', 'String', {DirEntries.name});
Now which ever image that i select in this pop up menu should be displayed in 'axes'
Can anyone help me on how to display the selected image in the GUI
Upvotes: 0
Views: 763
Reputation: 253
This code should do the job
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}));
Upvotes: 0