필터 지우기
필터 지우기

How to limit the movement of a rectangle?

조회 수: 1 (최근 30일)
BoSeon Kang
BoSeon Kang 2019년 11월 14일
댓글: BoSeon Kang 2019년 11월 15일
I use RectangleMovingEvent.
But I want to move the rectangle only vertically.
So I changed the values of PreviousPosition and CurrentPosition, but they are the same.
How do I limit the movement of the rectangle ??
roi = drawrectangle('Position',p ,'Color',[1 0 0]);
addlistener(roi, 'MovingROI', @(a, b)roi_moved(a, b, handles));
function roi_moved(hObject, eventdata, handles)
p = hObject.Position;

채택된 답변

Stijn Haenen
Stijn Haenen 2019년 11월 14일
maybe this will work:
roi = drawrectangle('Position',p ,'Color',[1 0 0]);
t=0;
while t<1
pause(0.15);pos=get(roi,'position');
set(roi,'position',[p(1) pos(2) p(3) p(4)])
t=t+0.01;
end
  댓글 수: 1
BoSeon Kang
BoSeon Kang 2019년 11월 15일
I solved it like this.
hObject.Position(1) = eventdata.PreviousPosition(1);
Thank you for the answer.

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

추가 답변 (1개)

Stijn Haenen
Stijn Haenen 2019년 11월 14일
Maybe you can use the function:
get(roi,'position')
But i'm not sure what you want.
  댓글 수: 1
BoSeon Kang
BoSeon Kang 2019년 11월 14일
I want to prevent the user from dragging the rectangle horizontally.

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

Community Treasure Hunt

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

Start Hunting!

Translated by