Create listener for changes in position of a figure window

9 Ansichten (letzte 30 Tage)
Matt J
Matt J am 17 Mai 2021
Kommentiert: Matt J am 18 Mai 2021
I have been trying to use addlistener() to make it so that when one figure window is moved, another figure window shifts position by the same amount, so that their relative positions are always the same:
h1=figure(1);
plot(1:5);
h2=figure(2);
imshow(imread('cameraman.tif'));
addlistener(h2,'Position','PostSet', @(s,e)callback(s,e,h1))
function callback(h2,~,h1)
h1.Position(1:2)=h2.Position(1:2)-[500,0];
end
However, this results in,
Error using matlab.ui.Figure/addlistener
While adding a PostSet listener, property 'Position' in class 'matlab.ui.Figure' is not defined to be
SetObservable.
Error in test (line 8)
addlistener(h2,'Position','PostSet', @(s,e)callback(s,e,h1))
Does anyone know of a workaround that will allow me to do this?

Akzeptierte Antwort

Jonas
Jonas am 17 Mai 2021
Bearbeitet: Rik am 17 Mai 2021

Weitere Antworten (0)

Kategorien

Mehr zu Graphics Object Programming finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by