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!