MATLAB Answers

0

Plot Line Over Multiple Axes Simultaneously

Hello all,
I am try to develop a GUI to play through data in time and examine different traces. Much like a audio recording interface. I'm having a difficult time getting the cursor behavior to work ok. I'm wondering if there is a better (faster) way to plot a vertical line over multiple plots rather than calling a for loop to loop through the axes. Here's what I mean (I define handles.cursor.xLocation from the mouse click position):
for j = 1:length(axesHandles)
axes(axesHandles(j))
yLimits = get(axesHandles(j),'YLim');
hCursor = line(handles.cursor.xLocation*[1 1],yLimits,'Color','r');
handles.cursor.handles(j) = hCursor;
end
This generates a considerable lag when plotting through this loop and was wondering if there was a better way??? Any help would be much appreciated!
Jeff

  0 Comments

Sign in to comment.

Products

1 Answer

Answer by Walter Roberson
on 1 Jul 2012
Edited by Walter Roberson
on 1 Jul 2012
 Accepted Answer

You mention "cursor behavior". Does that imply you are moving the lines? If so then it is better to set() the XData and YData of each of the lines rather than creating a new line() object each time.
You do not need the axes() call, and it is slowing you down. Instead, specify the axes in the line() call:
handles.cursor.handles(j) = line( handles.cursor.xLocation([1 1]), yLimits, 'Color', 'r', 'Parent', axesHandles(j) );
(I also optimized the *[1 1] that was being used for replication.)

  1 Comment

Thank you SO much!!! Works like a champ. And yes, that is exactly what I was doing is deleting and redrawing the cursor. Very inefficient. Your way is a great way of doing what I was trying to. Thank you so much for taking the time to post!!!!!

Sign in to comment.