Error using plot Vectors must be the same length.

4 次查看(过去 30 天)
Hi everyone,
I am trying to convolve two step function signals for school assignment the two signals are:
x(t) = (-t+3)(u(t)-u(t-3))
h(t) = 2u(t+2)-u(t+1)
I wrote the code below, when I ran the code I keep getting the "Error using plot
Vectors must be the same length.".the vector generated by the conv command is longer than the t vector!
any help will be appreciated.
clear all
clc
dt=0.01; t= -7:dt:6;
x = 2*heaviside(t+2)-heaviside(t+1);
h =(-t+3).*heaviside(t)-(-t+3).*heaviside(t-3);
y= dt.* conv (x,h);
plot(t,y)
whos
Name Size Bytes Class Attributes
dt 1x1 8 double
h 1x1301 10408 double
t 1x1301 10408 double
x 1x1301 10408 double
y 1x2601 20808 double
these are the values in my work space.

回答(1 个)

Star Strider
Star Strider 2019-11-22
To create ‘y’ to be the same length as ‘t’, use the 'same' shape argument in conv:
y= dt.* conv (x,h,'same');
  2 个评论
Star Strider
Star Strider 2019-12-25
Michael Darwish’s Answer moved here —
Thank you for your answer.
Star Strider
Star Strider 2019-12-25
My pleasure.
If my Answer helped you solve your problem, please Accept it!

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by