Need plot for time rather than samples

I am plotting a signal and need to do it with time on the X-axis. This is the code I used
Load Signal %load the appropriate signal
Fs = 200 ; %setting sample rate to 200
T = 1/Fs; %converting the sample to time
L1=length(Signal) ; %length of my signal (in this case its 4933)
plot(t,Signal);
when I do this I get an error saying not the same vector length.
Sorry for being a coding noob and thanks for you time :)

回答 (1 件)

Star Strider
Star Strider 2021 年 12 月 5 日

0 投票

If the time vector does not already exist, create it —
Signal = sin(2*pi*(0:999)*0.01) + randn(1, 1000); % Create 'Signal'
Fs = 200 ; %setting sample rate to 200
Ts = 1/Fs; %converting the sample to time
L1=length(Signal) ; %length of my signal (in this case its 4933)
t = linspace(0, L1, L1)*Ts; % Create Time Vector
dt = t(2) - t(1) % Verify Correct Sampling Interval (Delete Later)
dt = 0.0050
figure
plot(t,Signal)
grid
Experiment to get different results.
.

2 件のコメント

Gideon Fernandes
Gideon Fernandes 2021 年 12 月 5 日
Absolute genius. Once I read your code it made so much sense. Thanks this helped me tons
Star Strider
Star Strider 2021 年 12 月 5 日
My pleasure!
.

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

カテゴリ

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

質問済み:

2021 年 12 月 5 日

コメント済み:

2021 年 12 月 5 日

Community Treasure Hunt

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

Start Hunting!

Translated by