How to plot function part by part?
1 次查看(过去 30 天)
显示 更早的评论
So I want to set duration of plotting y=sin(t) to 10 seconds, but to plot it part by part every 2 seconds. So that means every 2 seconds plotting should be 'updated'.
I want to see how this work with basic function, because I want to apply it on plotting graph of winsound(sound card). It will also durate 10 seconds, and I need to update it every n seconds. So it is easier for me to see how this works on simple function such as sin(t). I hope you understood what I want to do, and I would be thankful if someone could solve my problem :)
采纳的回答
Walter Roberson
2019-3-17
编辑:Walter Roberson
2019-3-17
duration = 10;
Fs = 20; %samples per second
secs_per_plot = 2;
data = randi([-5 5], 1, duration*Fs); %example data for illustration
t_cols = reshape((0:Fs*duration-1)/Fs, Fs*secs_per_plot, []);
data_cols = reshape(data, Fs*secs_per_plot, []);
%the work
h = animatedline();
for K = 1 : size(data_cols,2)
addpoints(h, t_cols(:,K), data_cols(:,K));
drawnow();
pause(secs_per_plot);
end
6 个评论
Walter Roberson
2019-3-17
t_cols is already time in fraction of a second. Consider sin(2*pi*F*t) where F is the frequency of the sine wave and t is time in seconds.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!