How to make popup menu work with left mouse click in matlab GUI?

조회 수: 29 (최근 30일)
Hi
I am using the Matlab Guide tool for creation of GUI. I have created a pop-up menu in Guide tool and listed a 40 set of strings in the dropdown list in codes.
For eg:
A={'hi','bye'};set(handles.popupmenu_1,'string',string(A));
I have used the above code in the popupmenu_1 callback function. After I select the "hi" in the drop down list, the "bye" is displayed. I want to display all strings (hi & bye) once i made left mouse selection in the popup menu.
Even i have tried with "Buttondownfunction", there also i have a constraint that to prior selection of rightclick on the mouse button.
can someone suggest me how to do the left mouse selection displays all set of strings in the popmenu at very first time itself?
Pls let me know if need clarifications.

채택된 답변

Image Analyst
Image Analyst 2021년 8월 18일
Generally you'd list all 40 items to fill up the popup either in the String property of the popup in GUIDE, or you'd assign them and send them to the popup in your app's OpeningFcn() function. It's very strange to alter the popup contents in the callback itself, though it can be done.
You didn't say how you wanted the list of items to be "displayed". Do you want them in a string called txtPopup on the GUI?
handles.txtPopup.String = handles.popupmenu1.String;
Do you want to print them out to the command window?
popupStrings = handles.popupmenu1.String;
for k = 1 : numel(popupStrings)
fprintf('Item #%d is %s\n', k, popupStrings{k});
end
I don't believe you need to use Buttondownfunction at all.
  댓글 수: 3
Image Analyst
Image Analyst 2021년 8월 18일
In popup1's callback, you can get the strings somehow that you want to load into popup2. You don't need to do it in popup2's callback. Like if popup1 had a,b,c and popup2 had 1,2,3, and if the user picked b from popup1 you want popup 2 to be 400,500,600,700, you could set the popup2 string in popup1's callback, not popup2's callback. So callback 1 would look like
function popup1_Callback(hObject, event, handles)
if handles.popup1.Value == 2 % User selected second item 'b' from popup #1
% Assign strings in popup2.
handles.popup2.String = {'400', '500', '600', '700'};
end

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by