How can you add an image to a popupmenu using guide? An example picture of what I am trying to do is shown below. I have been trying to figure this out with no luck. Any help is appreciated.

 채택된 답변

Image Analyst
Image Analyst 2014년 11월 16일

2 개 추천

You can get that at Yair's site undocumented MATLAB.

추가 답변 (1개)

Jan
Jan 2014년 11월 15일

2 개 추천

You can include images using HTML:
Icon = fullfile(matlabroot,'/toolbox/matlab/icons/matlabicon.gif');
IconURI = ['"file:/', strrep(Icon, '\', '/'), '"'];
uicontrol('Style', 'popupmenu', ...
'String', {'Hello', ['<html><img src=', IconURI, '> String']})

댓글 수: 4

How would I implement this if I created the popupmenu using GUIDE? So I have something like:
% --- Outputs from this function are returned to the command line.
function varargout = Sections_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu3 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu3
Try
set(handles.popup1, 'String', {'Hello', ['<html><img src=', IconURI, '> String']})
Awesome, that seems to work. Now I just need to figure out how to adjust the spacing. The icon show's up almost on the text.
Is it better to leave the popupmenu strings empty and just reference them this way when using the images? So If I want to use there selection to perform operations such as:
contents = get(hObject,'Value')
switch contents
case 1
set(handles.edit1, 'Visible', 'off');
set(handles.text5, 'Visible', 'off');
case 2
% a=imread('11.png');
% imshow(a);
otherwise
end
That's not right. Look at the code in comments. What you call contents is actually the index that is selected. To get the contents and index:
selectedIndex = get(handles.popup1, 'Value');
allContents = get(handles.popup1,'string');
selectedContents = allContents{selectedIndex};

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

질문:

2014년 11월 14일

댓글:

2014년 11월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by