Superimpose two plots having different vector lengths

11 Ansichten (letzte 30 Tage)
Judicaël Fassaya
Judicaël Fassaya am 3 Mär. 2019
Kommentiert: Star Strider am 3 Mär. 2019
Hello,
I am new with Matlab and try using it for practicing pedagogy exercises about signal processing. Unfortunately I am stuck at this point :
I try to superimpose a chirp signal (signal with increasing frequency rate) and an aliased signal of this same chirp signal onto the same plot using the "hold on" function. Unfortunately an error occurs : "Error using plot ; Vectors must be the same length". I have tried several alternatives and read similar questions without understanding how to circumvent this little issue. I understand that there is some incompatibility between my two signals, related to their respective axes I guess. I put my code below for more understanding. Also, I precise that I only want to use the hold on function and not alternatives in order to learn how to use it :
Fs = 200 % sampling frequency
t = 0:1/Fs:1
x = chirp(t,0,1,Fs/6)
dx = x(1:20:end)
subplot(3,1,1,'align');
plot(t,x),
xlabel('Time(sec)');
ylabel('Amplitude');
title('Chirp Signal')
hold on; % here is my problem
plot(t,dx)
subplot(3,1,2); % display same plot with discrete values
stem(x)
subplot(3,1,3); % display the power of frequency components
pwelch(x)

Akzeptierte Antwort

Star Strider
Star Strider am 3 Mär. 2019
You need to make the ‘t’ vector the same length as the ‘dx’ vector. Thje easiest way to do that is to use the same decimation vector:
plot(t(1:20:end), dx)
That should work.
  2 Kommentare
Judicaël Fassaya
Judicaël Fassaya am 3 Mär. 2019
Indeed, I understand. Thank you a lot for your help.
Star Strider
Star Strider am 3 Mär. 2019
As always, my pleasure.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by