how to plot vectors of unequal length in matlab?

1 view (last 30 days)
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

Answers (1)

Cyrus
Cyrus on 28 Dec 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)

Categories

Find more on MATLAB in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!