how to plot vectors of unequal length in matlab?
1 次查看(过去 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
0 个评论
回答(1 个)
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)
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!