Info

此问题已关闭。 请重新打开它进行编辑或回答。

I'm having problem to adjust the range of the time to be from 0 to 10 , it shows me error in the vectors must be the same length and i don't know how to use the length function in matlab

1 次查看(过去 30 天)
T = 0.01;
time=[0:T:10];
h = exp(-time) - exp(-3*time);
x=(heaviside(-(-time+1))- heaviside(-(-time+4)));
y= conv(h,x)*T;
plot(y);
  1 个评论
Haidar AL Hassan
Haidar AL Hassan 2018-11-14
the range of the x axis should be 0 to 100 but when i plotted it showed me to 1000 however when i put in plotting function the time as plot(time, y) it shows me error

回答(1 个)

Mark Sherstan
Mark Sherstan 2018-11-14
The error is coming from using conv. As per MATLAB documentation it states:
>> help conv
conv Convolution and polynomial multiplication.
C = conv(A, B) convolves vectors A and B. The resulting vector is
length MAX([LENGTH(A)+LENGTH(B)-1,LENGTH(A),LENGTH(B)]). If A and B are
vectors of polynomial coefficients, convolving them is equivalent to
multiplying the two polynomials.
Therefore you are getting a vector of length(A) + length(B) - 1. This yields a vector of length 1x2001. Instead use element wise multiplication as follows:
T = 0.01;
time = [0:T:10];
h = exp(-time) - exp(-3*time);
x = (heaviside(-(-time+1))- heaviside(-(-time+4)));
y = (h.*x)*T;
plot(time,y);
This will yield a 1x1001 vector that can be plotted as required. To use the length function simply call length(), where the variable whos length you want to know goes between the brackets.

此问题已关闭。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by