Effacer les filtres
Effacer les filtres

how to plot vectors of unequal length in matlab?

2 vues (au cours des 30 derniers jours)
Dana Alsalman
Dana Alsalman le 28 Déc 2016
Réponse apportée : Cyrus le 28 Déc 2016
Hi,
I have the following and I need to plot in time domain
fs = 40; t1 = 0:( 1/fs ):6; S2 = [ sin( 2*pi*5*t1( t1<=2 ) ), sin( 2*pi*10*t1( 2<t1<4 ) ),sin( 2*pi*15*t1( t1>4 ) ) ];
plot(t1,S2)
I am getting an error because t1 and S2 have different lengths?
How can I make then equal in length to plot S2 in time domain?
Thanks, I really appreciate your help

Réponses (1)

Cyrus
Cyrus le 28 Déc 2016
You can make them equal in the following way, but you might want to assign any other value instead of "0" which best match your purpose.
fs = 40;
t1 = 0:( 1/fs ):6; S2 = [ sin( 2*pi*5*t1( t1<=2 ) ), sin( 2*pi*10*t1( 2<t1<4 ) ),sin( 2*pi*15*t1( t1>4 ) ) ];
for i = length(t1)+ 1 : length(S2)
t1(:, i) = 0;
end
plot(t1,S2)

Catégories

En savoir plus sur Graphics Performance dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by