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

26 次查看(过去 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