Display Marker for current Point in animated line

25 views (last 30 days)
I'm plotting hysteresis loops by a dataset with animatedline. How can I make the current plotted datapoint visible, with a Marker for example? I'm thinking of these:
My code:
h = animatedline;
x = mmatrix(:,2);
y = mmatrix(:,1);
for k = 1:length(x)
I tried to add a second addpoint but markers are all printed.

Accepted Answer

dpb on 30 Dec 2016
Edited: dpb on 30 Dec 2016
linestyle and other properties are global to a line; to have a different style/marker/color/whatever apply to only a single point will require that point be independent of the line. A scatter object would work for it; draw the line irrespective but w/o the marker then update the [X|Y]Data property for the scatter object to show the one point.
To do this all with HG2, you'd have to create a second animatedline with the desired marker style, color, etc., and then addpoints to its handle each iteration after you clearpoints the previous point of that handle; that appears to me likely to be more overhead intensive than the scatter solution suggested that just updates a single data array point albeit it mixes old and new styles...
Unfortunately, I am at R2012b which predates all this stuff so can't actually test here but there's not a method documented with animatedline to just modify a data point as you're needing to do here...
To illustrate, my solution would be sotoo--
hAL = animatedline; % line handle
% defaults for the marker
hAx=gca; % get the axis handle
sz=10; % size of marker
clr='b'; % color
hS=scatter(hAx,nan,nan,sz,clr); % initial point won't show but creates handle
x = mmatrix(:,2);
y = mmatrix(:,1);
for k = 1:length(x)
set(hS,'xdata',x(k),'ydata',y(k)) % update the marker position
See the doc's for scatter for other options, details...
Seems like this ability would be a reasonable enhancement request to the animated line going forward...why not submit this query to TMW as such?
Jan w
Jan w on 31 Dec 2016
your guess is right. I solved the pace problem:
drawnow limitrate
simple trick! Thanks

Sign in to comment.

More Answers (0)


Find more on Animation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by