필터 지우기
필터 지우기

Get the selected value in a popup menu with a set

조회 수: 22 (최근 30일)
jacques baptiste
jacques baptiste 2018년 4월 3일
댓글: jacques baptiste 2018년 4월 5일
Hello,
Is is possible to set the list of the popup menu (with set(handles.....)) and still get which one is selected? I did use set to have my different choices in the popup menu. But when i want to know which one is selected, it gives me the list that i had set... How can i get the selected value only?
if true
te = T(:,3); %one column of an excel file with number (101-109, 201-209,...409)
set(handles.popupname, 'String', table2array(te));
end
Thank you

채택된 답변

Geoff Hayes
Geoff Hayes 2018년 4월 3일
jacques - if you want to get the selected item you would first get the index of the selected value
idx = get(handles.popupname,'Value');
Once you have the index, you can then determine which is the selected item from your list
items = get(handles.popupmenu1,'String')
selectedItem = items{idx};
  댓글 수: 1
jacques baptiste
jacques baptiste 2018년 4월 5일
Thanks, i didn't know that i could have the index ! :)

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

추가 답변 (1개)

Image Analyst
Image Analyst 2018년 4월 3일
Try this:
allItems = handles.popupname.String; % A cell array of all strings in the popup.
selectedIndex = handles.popupname.Value; % An integer saying which item has been selected.
selectedItem = allItems{selectedIndex}; % The one, single string which was selected.
  댓글 수: 1
jacques baptiste
jacques baptiste 2018년 4월 5일
Thanks for answering too ! I did find the solution by using both answer :)

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

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by