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
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 件のコメント
回答 (1 件)
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.
0 件のコメント
この質問は閉じられています。
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!