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 :)

4 件のコメント

Walter Roberson
Walter Roberson 2019 年 3 月 16 日
animatedline() . Every 2 seconds addpoints() and drawnow()
Faris Hajdarpasic
Faris Hajdarpasic 2019 年 3 月 17 日
Can you paste code? I dont understand how to display it every 2 seconds
Walter Roberson
Walter Roberson 2019 年 3 月 17 日
outline:
while there is more to do
addpoints(....)
pause(2)
end
Faris Hajdarpasic
Faris Hajdarpasic 2019 年 3 月 17 日
But my action should be 10 seconds long. Is that what I should do in this "there is more to do"? I mean if duration is 10 seconds and every 2 sec I need to display part, I should run loop five times, and every time 1/5 of length should be displayed. Thats the point. So I can make it work like this?

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

 採用された回答

Walter Roberson
Walter Roberson 2019 年 3 月 17 日
編集済み: Walter Roberson 2019 年 3 月 17 日

0 投票

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 件のコメント

Faris Hajdarpasic
Faris Hajdarpasic 2019 年 3 月 17 日
編集済み: Faris Hajdarpasic 2019 年 3 月 17 日
It has error in line 9(you forgot underscore but it doesent work again)
Walter Roberson
Walter Roberson 2019 年 3 月 17 日
I have repaired the code, above.
Faris Hajdarpasic
Faris Hajdarpasic 2019 年 3 月 17 日
Now it works, but where is sinus? (it gives me some wierd shapes)
Sorry I am begginer, just started MATLAB
Walter Roberson
Walter Roberson 2019 年 3 月 17 日
The data I show is example data. You should replace it with your actual data.
I am not going to post the code because you are working on homework and you need to work out something yourself.
Faris Hajdarpasic
Faris Hajdarpasic 2019 年 3 月 17 日
I have been trying for whole day, this is why I asked cuz i couldnt figure it out.But thanks anyway
Walter Roberson
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 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by