How to find slope of this line

1 view (last 30 days)
I'm trying to find the slope of this linear line but I can't use polyfit because the vectors aren't the same size.
x = [0.0914;0.195;0.292];
y = [-2.89,-3.55,-2.88,-3.10,-3.09,-3.09,-3.28,-3.35;-7.65,-7.75,-7.43,-7.62,-7.60,-7.66,-7.32,-7.68;-11.2,-11.5,-11.6,-11.45,-11.5,-11.5,-11.5,-11.6];
grid on
xlabel('Distance-x (m)')
ylabel('Episilon(bottom)/Pj 1/N')
title('Thick Cantilever Negative')

Accepted Answer

Jos (10584)
Jos (10584) on 3 May 2019
You can create a complete list of x,y pairs by expanding x to the size of y. Looking at your code, I think a single element of x belongs to a row of y, so:
xx = repmat(x(:), 1, size(y,2))
polyfit(xx, y, 1)

More Answers (0)





Community Treasure Hunt

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

Start Hunting!