Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
movable/draggable line

Subject: movable/draggable line

From: Hoi Wong

Date: 5 Apr, 2009 01:55:03

Message: 1 of 3

Is there a simple way to create a draggable line (horizontal) and trigger a callback function when the line is moved? I tried imline(), but I was unable to prevent the users from moving the end points so that the line is slanted, nor the setPosition in the callback function does anything to move the line. Any suggestions? I also tried dualcursor in file central, but since my axes is in a panel, it breaks a lot of the functions inside.

Thanks in advance.

-- Hoi

Subject: movable/draggable line

From: Brett Shoelson

Date: 5 Apr, 2009 02:40:02

Message: 2 of 3

Hoi,
Try this:

>> p = imline;
>> setPositionConstraintFcn(p,@(pos) [pos(:,1) repmat(mean(pos(:,2)),2,1)])

Cheers,
Brett


"Hoi Wong" <wonghoi.ee@gmailNOSPAM.com> wrote in message
news:gr931n$60h$1@fred.mathworks.com...
> Is there a simple way to create a draggable line (horizontal) and trigger
> a callback function when the line is moved? I tried imline(), but I was
> unable to prevent the users from moving the end points so that the line is
> slanted, nor the setPosition in the callback function does anything to
> move the line. Any suggestions? I also tried dualcursor in file central,
> but since my axes is in a panel, it breaks a lot of the functions inside.
>
> Thanks in advance.
>
> -- Hoi

Subject: movable/draggable line

From: Hoi Wong

Date: 5 Apr, 2009 05:27:00

Message: 3 of 3

"Brett Shoelson" <bshoelso@mathworks.com> wrote in message <gr95lr$f3e$1@fred.mathworks.com>...
> Hoi,
> Try this:
>
> >> p = imline;
> >> setPositionConstraintFcn(p,@(pos) [pos(:,1) repmat(mean(pos(:,2)),2,1)])
>
> Cheers,
> Brett
>
>
> "Hoi Wong" <wonghoi.ee@gmailNOSPAM.com> wrote in message
> news:gr931n$60h$1@fred.mathworks.com...
> > Is there a simple way to create a draggable line (horizontal) and trigger
> > a callback function when the line is moved? I tried imline(), but I was
> > unable to prevent the users from moving the end points so that the line is
> > slanted, nor the setPosition in the callback function does anything to
> > move the line. Any suggestions? I also tried dualcursor in file central,
> > but since my axes is in a panel, it breaks a lot of the functions inside.
> >
> > Thanks in advance.
> >
> > -- Hoi
>

Thanks!! The documentation for imline and imroi needs a little bit more examples. I initially thought I need to set the position inside the function. :)

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us