フィルターのクリア

Display Marker for current Point in animated line

13 ビュー (過去 30 日間)
Jan w
Jan w 2016 年 12 月 29 日
コメント済み: Ankit Sahay 2019 年 5 月 19 日
Hello,
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;
h.LineStyle='-';
h.Color='blue';
x = mmatrix(:,2);
y = mmatrix(:,1);
for k = 1:length(x)
addpoints(h,x(k),y(k));
drawnow
end
I tried to add a second addpoint but markers are all printed.
Regards
  1 件のコメント
Ankit Sahay
Ankit Sahay 2019 年 5 月 19 日
What is "mmatrix" for?

サインインしてコメントする。

採用された回答

dpb
dpb 2016 年 12 月 30 日
編集済み: dpb 2016 年 12 月 30 日
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.
ADDENDUM
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
hAL.LineStyle='-';
hAL.Color='blue';
% 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)
addpoints(hAL,x(k),y(k));
set(hS,'xdata',x(k),'ydata',y(k)) % update the marker position
drawnow
end
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?
  3 件のコメント
dpb
dpb 2016 年 12 月 30 日
編集済み: dpb 2016 年 12 月 30 日
Well, is it too fast or too slow? :)
I guess what you're actually saying is too slow as written above, too fast if use the 'limitrate' option?
Unfortunately, as I noted above, I am at R2012b which doesn't have any of the HG2 stuff so I can't do anything with it other than read the doc. If it's too slow without the option, I don't expect there's too much to gain unless there's more besides simply the drawing loop you've shown that could somehow be shortened. It doesn't surprise me at all that it would slow down as more points are added; underneath the hood I'd guess it's very similar with just cleaner syntax to what is done simply by augmenting the [X|Y]Data properties for a line handle object.
OTOH, if it is to try to slow it down for presentation purposes if you use the drawnow option, you can always try a pause in the loop for a fraction of a second and see what happens...
Jan w
Jan w 2016 年 12 月 31 日
your guess is right. I solved the pace problem:
...
drawnow limitrate
pause(0.01)
simple trick! Thanks

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAnimation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by