Borrar filtros
Borrar filtros

addlistener in R2014b can't access new property value?

3 visualizaciones (últimos 30 días)
matt dash
matt dash el 5 de Nov. de 2014
Comentada: Reto Zingg el 15 de Abr. de 2015
Is addlistener useless in 2014b? See example below. In older versions the "ev" input to the listnn function would have a field containing the new value that the property is being set to (ev.NewValue)... but in 2014b I don't see the new property value anywhere in the listnn function's inputs.... which seems to defeat the purpose of having listeners...
Is there some new method to get the new property value?
function listenertest
figure
a=axes('xtick',[0 .5 1])
addlistener(a,'XTick','PreSet',@listnn)
set(a,'xtick',[.1 .2 .3 .4]) %<-- triggers listener
function listnn(src,ev)
keyboard %<-- can't find [.1 .2 .3 .4] anywhere
  1 comentario
Reto Zingg
Reto Zingg el 15 de Abr. de 2015
Matt, have you found a solution to the problem? I have the exact same issue. I used to listen for a change in XTick to change the labels (e.g. 1000 -> 1k). But as you mentioned, resizing or paning the plot does not fire the listener anymore...

Iniciar sesión para comentar.

Respuestas (2)

Doug Hull
Doug Hull el 6 de Nov. de 2014
Editada: Doug Hull el 6 de Nov. de 2014
So this will work, since you know the values you want int there, pass them in like any other argument to the call back.
function listenertest
figure
a=axes('xtick',[0 .5 1])
nv = [.1 .2 .3 .4];
addlistener(a,'XTick','PreSet',@(o,e)listnn(o,e,nv))
set(a,'xtick',nv) %<-- triggers listener
function listnn(src,ev,newval)
keyboard %<-- can't find [.1 .2 .3 .4] anywhere
  1 comentario
matt dash
matt dash el 6 de Nov. de 2014
Well, that works for this example, but in general i use listeners on xtick/ytick/ztick to do something when the ticks have changed as a result of the axes being resized while the tickmodes are auto. Although i now realize that in 2014b the listener does not run when xtick changes due to axes resizing (it did in older versions); it only runs if you explicitly set the xtick as in the example above. Looks like i need to experiment more to find a workaround for what i need.
(E.g. in old versions, resizing the figure would beep, but in 2014b it never beeps:
function listenertest
figure
a=axes('xtickmode','auto')
addlistener(a,'XTick','PreSet',@listnn)
function listnn(src,ev)
beep

Iniciar sesión para comentar.


Sean de Wolski
Sean de Wolski el 6 de Nov. de 2014
Editada: Sean de Wolski el 6 de Nov. de 2014
The NewValue event property is gone in R2014b. It is probably a release notes bug that it's not in there.
Why do you want it? It only affects the PreSet event, in the PostSet event you can query the value directly.
  2 comentarios
matt dash
matt dash el 6 de Nov. de 2014
Yeah... basically i have a function that needs both the pre and post values. In the old versions you could get these both in a preset listener. I was thinking that one option would be to use a preset listener to store the "pre" value, and then a postset listener to get the "post" value and run the function on both the pre and post values. But as my comment above explains, the event i'm trying to listen to no longer triggers the listener, so i'll have to go another route entirely.
Sean de Wolski
Sean de Wolski el 6 de Nov. de 2014
I would wrap another class around the axes or uicontrol that stores the old/new values.

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by