Info

This question is closed. Reopen it to edit or answer.

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 view (last 30 days)
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 Comment
Haidar AL Hassan
Haidar AL Hassan on 14 Nov 2018
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

Answers (1)

Mark Sherstan
Mark Sherstan on 14 Nov 2018
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.

This question is closed.

Tags

Community Treasure Hunt

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

Start Hunting!