Creating an event for "DrawRectangle" such as right click on mouse
70 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hello, i am drawing 2 rectangles on an image
ax=app.UIAxes; % Axes that image is on
numROIs = 2;
roiPos = zeros(numROIs,4);
for cnt = 1:numROIs
hrect = drawrectangle(ax);
roiPos(cnt,:) = hrect.Position;
cnt
end
I want to be able to perform a calculation (e.g standard deviation) of each region by a right click or something else rather than a ROImoving or ROImoved event. (the reason is I dont want the calcs firing off whilst moving or e.g one rectangle is in position (stopped moving) but the 2nd rectangle still needs to be positioned)
Any pointers, I see the below but I can't find a right mouse click event or some other suggestion
addlistener(roi,'MovingROI',@allevents);
addlistener(roi,'ROIMoved',@allevents);
function allevents(src,evt)
evname = evt.EventName;
switch(evname)
case{'MovingROI'}
disp(['ROI moving previous position: ' mat2str(evt.PreviousPosition)]);
disp(['ROI moving current position: ' mat2str(evt.CurrentPosition)]);
case{'ROIMoved'}
disp(['ROI moved previous position: ' mat2str(evt.PreviousPosition)]);
disp(['ROI moved current position: ' mat2str(evt.CurrentPosition)]);
end
end
10 Commenti
dpb
il 18 Nov 2025 alle 19:06
Modificato: dpb
il 18 Nov 2025 alle 21:49
It appears you would have to look at the area on which the click occurs as well and take action if click the face area instead of edge. Does appear to be very complicated to do anything with, agreed.
Keep digging at the doc, there's also an example with using a wait that might be of some interest in being able to control what happens when after the initial selection click ... in it, they unassign the initial callback function before resuming code -- maybe that's the key.
I really don't know and don't have any way to try it out not having the toolbox.
The other thread about reaction time may have something of interest, too....I wasn't aware of it, but waitforbuttonpress programmaticallly shifts the focus to the figure without a manual keystroke/mouse click...maybe that would be the way to be able to avoid the selection ROI click you're now getting that isn't of interest.
Or, another thought -- maybe the callback should first be on the 'ROISelected' property and only then set the ROI Click callback inside it once the ROI is selected...I dunno, this is far more involved than I've ever tried to build a GUI.
Risposte (0)
Vedere anche
Categorie
Scopri di più su Axis Labels in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

