what event to use in addlistener for a popupmenu

2 vues (au cours des 30 derniers jours)
Yitian Zhang
Yitian Zhang le 29 Août 2022
Réponse apportée : chrisw23 le 30 Août 2022
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

Réponses (1)

chrisw23
chrisw23 le 30 Août 2022
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

Catégories

En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by