Get from Ico-github-logo

Highlights from

  • dualcursor(state,deltalab...
    dualcursor Add dual vertical cursors to a plot
  • View all files


4.6 | 25 ratings Rate this file 31 Downloads (last 30 days) File Size: 10.9 KB File ID: #2875
image thumbnail




20 Dec 2002 (Updated )

Add dual vertical cursors to a plot.

Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

| Watch this File

File Information

Dual cursors are useful for picking relative measurements off of a plot; for instance - calculate the period of a time series, or the relative amplitude of two frequencies. A picture's worth a thousand words, so take a peek.
Key Features:
 - Basic syntax: dualcursor on / dualcursor off
 - Extended syntax supports a high level of control
 - Works with live data streams
 - Works in GUIDE guis
 - Includes delta calculations (x2-x2, y2-y1)
 - Export selected region to a new figure or to the workspace


This file inspired Stackobj, Dualcursor2, Speech Analysis Using Lpc, and Dtmcursor.

Required Products MATLAB
MATLAB release MATLAB 7 (R14)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (36)
23 Oct 2014 Michelle Hirsch

@Douglas Anderson - I updated the code several months ago to work with R2014b. Have you downloaded the latest version? If so, please let me know what problems you are encountering.

23 Oct 2014 Douglas Anderson

Hello again!

With 2014b, there are some changes, and this code is having a lot of problems!

Any thoughts? Have you tried it now?

28 Sep 2014 Rajeev Yadav

Wonderful... I was told about this post by Yair Altman the MATLAB veteran. I guess, the title messed it up in search ...

Nice work, keep it up.

21 Feb 2014 Douglas Anderson

Thank you for this function. I have been using it for a while. It is very good for windowing datasets, but that means you need to move the left datalabel out of the way (to the left) every time you use it. How do you set up the position of the datalabel for this application?

Also, can the Del_x and Del_y be simply eliminated, if not needed?

Thanks! Great work. (five stars)

20 Jan 2014 Michelle Hirsch

I sent Mayank a version that supports this. If it goes well for him, I will post this updated version to the File Exchange.

15 Jan 2014 Mayank Amencherla

Hi, I have about 17 or 18 plots on my GUI, and I'd like to remove the Del_x and Del_y text completely from all but 1 of the graph. Is there a way I can do this?

13 Jan 2014 Michelle Hirsch

Mark - glad you like it. The code doesn't do horizontal lines. It could be modified to do so, but would likely be a fair bit of work since my code all assumed vertical lines.

If anybody is up for tackling I'd be happy to review proposed changes! Just email me.

13 Jan 2014 Mark Jackson

This is a superb bit of code! Is it possible to do horizontal lines? That would be a great addition.

20 Dec 2013 Rudi Setiawan  
11 Sep 2013 Matthew

Great tool and something similar should be part of MATLAB release.

12 Jul 2013 Jonathan Lister

Clicking on one of the copied lines in the new figure causes the failure.

12 Jul 2013 Jonathan Lister

This is a great tool. I did find one bug. When a user exports a region to a new figure it appears that the copied lines retain the 'selected' callback and the 'update' case fails due to no cursors on the new plot. I fixed this issue by modifing the first few lines of the 'update' case to be:

case 'update' %Update the cursor value
%Find the position of the existing cursors

cursors = findobj(axh,'Tag','Cursor');

if isempty(cursors)

28 May 2013 Aditya

Great utility. I especially like how it is easy to right click and export the data.

Can this utility work with subplots and multiple lines within each subplot?

I run into this a lot when looking at test data obtained from DAQ hardware or even when looking at simulation results.

Have you considered incorporating this feature into a utility "ssc_explore" that Atul Suri from Mathworks created?

28 May 2013 Aditya  
13 Mar 2013 Danielle

flexible, useful and generic. Absolutely amazing!

19 Jan 2012 Preston

Would it be possible to expand callback functionality so that I could call it within a GUI whenever a cursor was moved?

29 Dec 2011 Francis

Another vote for horizontal cursors.

07 Nov 2011 fatanssi mohamed  
07 Nov 2011 fatanssi mohamed

I would like to thank you very much for this precious work. And I need to ask you how we can have an additionnaly horizontal dual cursor at the same time in the same plot
Sincerly your's

30 Sep 2011 rasam aliazizi  
30 Sep 2011 rasam aliazizi

was gga do that my self but hey now i have it, thanks....

08 Mar 2010 CĂ©dric DuchĂȘne

Thank you very much for this tool.

Is it possible to use this function on the horizontal axis ?
How do you think it should be difficult to add this ability to work in this case ? (Toogle mode vertical <--> horizontal)

Thank you again.

27 Oct 2009 Roy

If you have multiple plots in one figure how do you select which one to select?
Really nice work.

15 Apr 2009 Scott

Is it possible to have this function be "modal". For instance, if I wanted to use this function in a script that asks the user to set the lower and upper bounds of interest using dualcursor, how do I have my code stop and wait for the user to slide the vertical bars to the appropriate locations? I guess I need a button added to the plot so that the program waits until the limits are set before the user hits the "submit" button?

04 Apr 2009 Hoi Wong

It seems like the program doesn't like figures being a child of uipanel:

??? Error using ==> set
There is no 'WindowButtonDownFcn' property in the 'uipanel' class.

Error in ==> dualcursor at 688

Error in ==> dualcursor at 220

Error in ==> episodesPanel>slider_strip_Callback at 147
dualcursor([1 2], handles.panel.episodes.infoDisplay.axes_electrogram);

??? Error while evaluating uicontrol Callback

??? Error using ==> uicontextmenu
An object of class uicontextmenu, can not be a child of class uipanel.

Error in ==> dualcursor at 325
cmenu = uicontextmenu('Parent',get(axh,'Parent'));

Error in ==> episodesPanel>slider_strip_Callback at 147
dualcursor([1 2], handles.panel.episodes.infoDisplay.axes_electrogram);

30 Jul 2008 nicolas billard

Excellent. Only 1 thing : When i compile a soft which calls dualcursor, it turns. But it canno't turn when i deploy the soft on target pc with matlab runtime. May be it's due to the crypto aspect of dualcursor which is again crypted by compilation. Is it a solution for it?

26 Apr 2005 Tony Rainoldi

works great

31 Mar 2005 Friedhelm Steinhilber


20 Jul 2004 Alex Boboc


03 Aug 2003 Frank Hart

Not working for me. Shame, too, it could be so useful. I am using Matlab R11 (5.3), and
when I run the sample code and then call
dualcursor, I get this message back:

??? labelformatfcnh = @
Missing variable or function.

Syntax error in ==> C:\MATLAB_SR11\central\dualcursor.m
On line 147 ==> datalabelformatfcnh = @local_maketextstring;

26 Apr 2003 Paul Koola

Cool Tool

13 Mar 2003 thomas toth

my plot contains multiple data sets (used hold on). is there a way to set the cursors on two different graphs as data source?
eg. measure x/y difference between two points on two graphs (data) within the same plot. could maybe done using left/right click of mouse?

12 Mar 2003 thomas toth

Very nice tool. Just what I needed for my data evaluation and extraction. Now it's as good as any simulation tool. Thanks for the tool.

13 Jan 2003 Lisa Barker

Works great

26 Dec 2002 Poh Chee Khun

This is what I am looking for!

23 Dec 2002 Denis Gilbert

Neat program for interactive data exploration !

07 Jan 2003

Small bug fix: Eliminated error when user clicked on the figure background.

14 Mar 2003

Small bug fix: Eliminated error when clicking on a line AFTER dualcursor has been turned off. Thanks to Hao Fang for catching this.

06 Jun 2003

Small bug fix: Eliminated error when clicking on a line AFTER dualcursor has been turned off. Thanks to Hao Fang for catching this.

09 Sep 2009

Enhancement - now works when axes is parented to uipanel.

16 Sep 2009

Small fix - now works when the axes is parented to a uipanel, too (I wrote the original back in the day when the figure was the only parent an axes ever had ...)

21 Oct 2009

A few small updates based on user feedback.

28 Oct 2009

A few small feature requests.

21 Sep 2011

Removed hype from description.

11 Sep 2013

Enhanced support for zoom and pan. If you zoom or pan such that the cursors go off screen, they are automatically brought back in to the visible part of the axis. Good stuff.

17 Jun 2014

Moved code to GitHub. Removed mistaken attribution.

Contact us