MATLAB: Matrix Indexing for calculating slope

MATLABmatrix manipulation

Ive got 2, 31×1 matrices x and y to represent x and y points
Id like to calculate the slope of the data by using m = y2 – y1/x2 – x1 and average the slopes obtained
My question is how can i use the second and first value of data of both x and y to calculate the slope for each point throughout the whole data set

Best Answer

slope=diff(y)./diff(x);
averageSlope=sum(slope)/length(slope);
Related Question