How to find slope of this line

4 views (last 30 days)
jaad shahout
jaad shahout on 3 May 2019
Answered: Jos (10584) on 3 May 2019
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];
plot(x,y,'o')
grid on
xlabel('Distance-x (m)')
ylabel('Episilon(bottom)/Pj 1/N')
title('Thick Cantilever Negative')
polyfit(x,y,1)

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)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Tags

Products


Release

R2017a

Community Treasure Hunt

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

Start Hunting!