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!
