how to plot vectors of unequal length in matlab?

3 次查看(过去 30 天)
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

回答(1 个)

Cyrus
Cyrus 2016-12-28
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)

类别

Help CenterFile Exchange 中查找有关 Graphics Performance 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by