Get from Ico-github-logo

Highlights from
dualcursor

  • dualcursor(state,deltalab...
    dualcursor Add dual vertical cursors to a plot
  • View all files
4.65217
4.7 | 26 ratings Rate this file 29 Downloads (last 30 days) File Size: 10.9 KB File ID: #2875 Version: 1.9
image thumbnail

dualcursor

by

 

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
Description

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

Acknowledgements

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 (45)
08 Jun 2015 Michelle Hirsch

Artem - very nice refinement. I have updated the submission to include this change.

Comment only
08 Jun 2015 Artem Kabannik

Michelle,

Thanks for your reply and giving me a hint where the problem was. I worked with serial date numbers where the absolute values are much higher order of magnitude than the interval.

So the line:

xLimits = xlim(axh).*[1.02 .98];

in the repositionCursors function gave me totally wrong cursor positions. I changed it to:

xLimits = xlim(axh) + diff(xlim(axh))*[.02 -.02];

Where the smaller interval is based on the old interval, rather than on the absolute values of the edges. Now your feature of snapping cursor turned out to be very useful in my application, please do not change it.

Thanks again for a quick response,
Artem

Comment only
05 Jun 2015 Michelle Hirsch

Artem - That was supposed to be a feature that the cursor would snap back onto screen if it ended up off of the screen for some reason! I'm not exactly sure why I added it, but I definitely put it there on purpose :).

Sorry that this doesn't work for you - I certainly can understand that there are use cases where you'd want them to stay still. Maybe this is what everybody would want, but I'm not sure. I'll leave the code as it is for now, but if I hear from others that the behavior feels wrong I'm happy to change it.

In the meantime, you should be able to get the behavior you'd like by simply commenting out one line:

Line 787, the last statement in the repositionCursors function.

Here's what you will see:
% Put cursors in new positions
dualcursor(xCursors)

Add a comment at line 787 so it looks like
% Put cursors in new positions
% dualcursor(xCursors)

Let me know if this works for you.

Comment only
05 Jun 2015 Artem Kabannik

Michelle,

I am using your dualcursor on R2014b (8.4.0.150421). What I found running the example from the dualcursor code, that if the cursors go off screen when zooming in or panning, they appear at wrong places after zooming out. Could you please fix this bug for me?

Thanks,
Artem

Comment only
27 Apr 2015 Michelle Hirsch

Tjitske - could you provide more specific information about what issues you are encountering? I last updated this to work with R2014b, and verified that it also appears to work with R2015a.

Comment only
20 Apr 2015 Tjitske Boonstra

Hi Michelle,

Have you updated yet to Matlab 2015? I am experiencing problems using your function in this version of Matlab.

Thanks,
Tjitske

Comment only
05 Jan 2015 Michelle Hirsch

@Rilin:

Dualcursor is designed to work in individual lines in plots. The pair of cursors can take differential measurements in two locations on a single line only, not across multiple lines. It’s not working for you since your plot contains multiple lines (one created every time through the for loop).

I can’t recommend a strong alternative since it’s not clear to me from this example what you are trying to achieve with the way you have put multiple lines side-by-side. Depending on what you are trying to do, one possibility would be to concatenate all of the data into a single vector that you plot once, e.g.

t1 = 0:.1:10;
t2 = [];
y = [];
figure;

for i =0:5
t = i*10+t1;
t2 = [t2 t];
y = [y sin(2*pi*t)];
end

plot(t2,y);

dualcursor

Comment only
04 Jan 2015 Rilin

Rilin (view profile)

Hello, thanks for your job. I have try dualcursor.m by following code. But why the dualcursors can only moving in a rang just like range [0 10],range [10,20]
and etc.? It cannot cover the whole range [0 60] in this example.
t1 = 0:.1:10
figure;

for i =0:5
t2 = i*10+t1;
y = sin(2*pi*t2);
plot(t2,y);
hold on

end
dualcursor

Comment only
31 Dec 2014 Rilin

Rilin (view profile)

Hello, thanks for your job. I have try dualcursor.m by following code. But why the dualcursors can only moving in a rang just like range [0 10],range [10,20]
and etc.? It can cover the whole range [0 60] in this example.
t1 = 0:.1:10
figure;

for i =0:5
t2 = i*10+t1;
y = sin(2*pi*t2);
plot(t2,y);
hold on

end
dualcursor

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.

Comment only
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?

Comment only
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.

Comment only
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.

Comment only
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.

Comment only
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.

Comment only
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)
dualcursor('on',[],[],[],axh);
return
end

28 May 2013 Aditya

Aditya (view profile)

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

Aditya (view profile)

 
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.

Comment only
27 Oct 2009 Roy

Roy (view profile)

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

15 Apr 2009 Scott

Scott (view profile)

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?

Comment only
04 Apr 2009 Hoi Wong

Hoi Wong (view profile)

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
set(get(axh,'Parent'),'WindowButtonDownFcn','','WindowButtonUpFcn','')

Error in ==> dualcursor at 220
dualcursor('off',[],[],[],axh);

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);

Comment only
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

super!

20 Jul 2004 Alex Boboc

excelent

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;

Comment only
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?

Comment only
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 !

Updates
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 1.1

Enhancement - now works when axes is parented to uipanel.

16 Sep 2009 1.2

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 1.3

A few small updates based on user feedback.

28 Oct 2009 1.4

A few small feature requests.

21 Sep 2011 1.6

Removed hype from description.

11 Sep 2013 1.8

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 1.9

Moved code to GitHub. Removed mistaken attribution.

Contact us