what event to use in addlistener for a popupmenu

1 次查看(过去 30 天)
Hello I have created the following code to do some simple task:
  1. Using the slider. The addlistener will detect the change of value on the slider, and plot a point in makeplot_filter function, with x and y value equal to the slider value.
  2. I want to do the same thing with the popup menu (currently commented). There are four values in the dropdown menu, 1, 2, 3, 4. When a value is selected from the dropdown menu, I would like to have another point added, with x and y value equal to the selected value.
Right now I don't know what event I should listen to for this popup menu. I would like to know where in the help documentation I can find all the available event names for pop up menu.
clear all
close all
clc
figure('Name','Filtered image','NumberTitle','off','units','normalized','outerposition',[0.5 0.5 0.5 0.5])
hold on
h = uicontrol('style','slider','units','normalized','position',[0.01 0.85 0.2 0.05],'Min',0.2,'Max',5,'Value',1);
addlistener(h,'ContinuousValueChange',@(hObject,event) makeplot_filter(hObject,event));
% h = uicontrol('style','popupmenu','string',{'1','2','3','4'},'units','normalized','position',[0.01 0.85 0.2 0.05]);
% addlistener(h,'PropertyAdded',@(hObject,event) makeplot_filter(hObject,event));
function makeplot_filter(hObject,event)
hObject.Value
plot(hObject.Value,hObject.Value,'r*')
end

回答(1 个)

chrisw23
chrisw23 2022-8-30
h2 = uicontrol('style','popupmenu','string',{'1','2','3','4'},'units','normalized','position',[0.01 0.85 0.2 0.05]);
h2.Callback = @makeplot_filter;
here's the link to the Matlab doc

类别

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