필터 지우기
필터 지우기

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

조회 수: 4 (최근 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일
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.

댓글을 달려면 로그인하십시오.

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by