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

2 ビュー (過去 30 日間)
Ali razi
Ali razi 2021 年 12 月 30 日
編集済み: Ali razi 2021 年 12 月 31 日
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
  1 件のコメント
Image Analyst
Image Analyst 2021 年 12 月 30 日
I don't know. We can't reproduce because you didn't attach the .mlapp file.

サインインしてコメントする。

回答 (1 件)

Image Analyst
Image Analyst 2021 年 12 月 30 日
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 件のコメント
Ali razi
Ali razi 2021 年 12 月 30 日
Its to remove the the initial empty handle (
https://www.mathworks.com/matlabcentral/answers/1619365-extract-position-of-all-draw-points
)
Ali razi
Ali razi 2021 年 12 月 31 日
I updated the question and the mlapp.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeApp Building についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by