Trying to create a natural log animation plot that shows the data points using the delay function

I came across an interesting code yesterday that created a natural log plot that used the delay function to plot the points of the graph slowly. Unfortunately I can not find this code and have been trying to replicate it on my own. As of now I have the following
x = (0:0.2:10);
y = log(x);
delay (0:0.1);
for i = 1:numel(x)
plot(i,y(i));
drawnow
end
However this code is not working and I'm a bit rusty at coding in matlab and would really appreciate some help.
Thank you

1 件のコメント

Alexander
Alexander 2016 年 3 月 11 日
編集済み: Alexander 2016 年 3 月 11 日
I found the code again on stackoverflow and I give all credit to a Jacob.
clear all; clc;
x = 1:0.2:100;
y = log(x);
DELAY = 0.0001;
for i = 1:numel(x)
clf;
plot(x,y)
hold on;
plot(x(i),y(i),'go');
pause(DELAY);
end

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

 採用された回答

All credit to Jacob on stackoverflow
clear all; clc;
x = 1:0.2:100;
y = log(x);
DELAY = 0.0001;
for i = 1:numel(x)
clf;
plot(x,y)
hold on;
plot(x(i),y(i),'go');
pause(DELAY);
end

その他の回答 (1 件)

Perhaps you are thinking of something like
x = (0:0.2:10);
y = log(x);
xlim([x(1), x(end)]);
ylim([-4, y(end)]);
hold on
for i = 1:numel(x)
plot(x(i),y(i), '*');
pause(0.1);
end

4 件のコメント

Alexander
Alexander 2016 年 3 月 11 日
Thank you for the reply, this is very similar to what I came across the other, however the code I am trying to replicate had used the delay function which allowed me to speed up and slow down the animation. Also there was a line graphed onto the plot as well and there was a single star that followed the line plot from the limits.
I was not able to find any function named "delay" in any of the toolboxes. I found Delay blocks for Simulink, and Delay having to do with some signal processing, but nothing that would affect animation. Is it possible you were looking at something that used PsychTools, the toolbox for psychometric experiments?
Alexander
Alexander 2016 年 3 月 11 日
I don't believe so, it was just an animated line for a log function. There is a code called animatedline, but the version of matlab I use here at school doesn't have it installed.
The following solution has something similar to what I am trying to accomplish. http://www.mathworks.com/matlabcentral/answers/243381-animate-line-but-show-marker-only-on-current-point
clear all;clc;
x = (0:0.2:10);
y = log(x);
DELAY = 0.001;
for i = 1:numel(x)
p=plot(x(i),y(i),'*');
comet(x,y);
pause(DELAY)
end
I came across the comet function, however the animation is sporadic

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

カテゴリ

ヘルプ センター および File ExchangeAnimation についてさらに検索

質問済み:

2016 年 3 月 10 日

回答済み:

2016 年 3 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by