Refresh positions of all draw points after deleting or moving - App designer

2 views (last 30 days)
Following my last question (https://www.mathworks.com/matlabcentral/answers/1619365-extract-position-of-all-draw-points) I did an app designer GUI with two buttons and axes. The first one (LoadimageButton) is loading the pappers image and I can mark points until I press escape. The second button is printing out the point coordinates (PositionButton).
I have noticed that after pressing the two buttons I can move points in the axes and change their positions or delete them. The issue is that when I press the delete (in the context menu) I get this error after pressing the PositionButton:
Error using images.roi.Point/get
Invalid or deleted object.
Error in tempDrwPnt1/PositionButtonPushed (line 61)
positions = cell2mat(get(app.pointhandles, 'position'))
Error while evaluating Button PrivateButtonPushedFcn.
How can I refresh the app.pointhandles after deleting a point?
Code:
function LoadimageButtonPushed(app, event)
imshow('peppers.png','Parent',app.ImageAxes);
userStopped = false;
app.pointhandles = gobjects();
while ~userStopped
roi = drawpoint(app.ImageAxes);
if ~isvalid(roi) || isempty(roi.Position)
% End the loop
userStopped = true;
else
% store point object handle
app.pointhandles(end+1) = roi;
end
end
addlistener(roi,'MovingROI',@allevents);
addlistener(roi,'ROIMoved',@allevents);
app.pointhandles(1) = [];
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
end
% Button pushed function: PositionButton
function PositionButtonPushed(app, event)
positions = cell2mat(get(app.pointhandles, 'position'))
end

Answers (1)

Image Analyst
Image Analyst on 30 Dec 2021
Not sure what's going on here:
app.pointhandles(1) = [];
positions = cell2mat(get(app.pointhandles, 'position'))
How can you get the position property of pointhandles when you just set it to null? It throws an error. Why are you setting it to null?
  2 Comments
Ali razi
Ali razi on 30 Dec 2021
Its to remove the the initial empty handle (
https://www.mathworks.com/matlabcentral/answers/1619365-extract-position-of-all-draw-points
)

Sign in to comment.

Categories

Find more on App Building in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!