MATLAB 'Error using plot Vectors must be the same length.'

前端 未结 1 1129
慢半拍i
慢半拍i 2021-01-27 18:23
x = 0:1:5; % define x array 
y = exp(x)+x.^4+2*x.^2-x+3; % define y array
dx = diff(x); % 1 1 1 1 1 dx has one number less than x 
dy = diff(y); % -5 -1 -3 -4 -2
slope =         


        
相关标签:
1条回答
  • 2021-01-27 18:32

    Since slope is computed from two consecutive values, I suggest you take the average betwen consecutive points as the x-axis values for ´slope`:

    plot((x(1:end-1)+x(2:end))/2,slope, '*',x,z)
    

    enter image description here

    0 讨论(0)
提交回复
热议问题