Creating a popup menu through a function.

7 次查看(过去 30 天)
I am creating a pop up menu in matlab to find different things related to probability the function needs compute the Sum of probabilities if selcted and return for the user to make another choice and end if the user selects quit. I am not sure if I am doing this correctly at all. just looking for some pointers to ensure I am on the correct path. I am also trying to avoid using GUI if possible
This is my code so far:
function y = p3(X,P)
countX = numel(X);
countP = numel(P);
if countX~=countP
error('Different number of outcomes and probabilities');
end
if countX == countP
h_fig = figure;
h_popup = uicontrol(...
'Style','popupmenu',...
'String',{'Sum of Probabilities','Expected Value','Variance','Standard Deviation', 'Quit'},...
'Callback',@mypopup_fcn,...
'Units','normalized',...
'Position',[0 0.5 1 0.5]);
h_textbox = uicontrol(...
'Style','edit',...
'Units','normalized',...
'Position',[0 0 1 0.5]);
function changetype(hObj,~)
case 1
s = sum(P);
h_textbox = ('The sum of the probabilities are ')
end
end
  1 个评论
Jan
Jan 2022-11-14
"I am also trying to avoid using GUI if possible" - there are no popup menus without a GUI. So what does this mean?
The function changeType is not used, but mypopup_fcn is missing.
A case 1 requires a switch command before.
h_textbox = ('The sum of the probabilities are ')
I assume you mean:
h_textbox.String = sprintf('The sum of the probabilities are %g', s);

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by