how to do a line progression of line trend.

So i have a line plot from an two arrays X = [52.5, 81.25, 86.25, 106.5]; and Y= [787.5, 1228.13, 1361.25, 1796.26, 1233.75];. How am I able to map their progression if the trend where to keep on going.

 Risposta accettata

First, you cannot, because your ‘X’ vector is (1x4) and your ‘Y’ vector is (1x5). Deleting the last element of ‘Y’, fitting a linear model, and extrapolating, try this:
X = [52.5, 81.25, 86.25, 106.5];
Y= [787.5, 1228.13, 1361.25, 1796.26];
B = [X(:) ones(size(X(:)))]\Y(:);
Xv = linspace(-100, 250);
Yv = [Xv(:), ones(size(Xv(:)))] * B;
figure(1)
plot(X, Y, 'pg')
hold on
plot(Xv, Yv, '-r')
hold off
grid

4 Commenti

Yes sorry about that I was missing a data point. Can you just explain what B is equal too. Thanks in advance
As always, my pleasure.
No worries!
In my code, ‘B’ are the regression coefficients. As I coded it, ‘B(1)’ is the slope, and ‘B(2)’ is the intercept of a linear regression fit to your data. It is a column vector, so multiplying it by the original design matrix (here [X(:) ones(size(X(:)))]) will produce a linear fit to your data.
I could have instead used:
B = polyfit(X, Y, 1);
and:
Yv = polyval(B, Xv);
however chose not to in order to explore a different (and for this problem, more efficient) option.
Okay I got it. Does clarify how the whole code works.
Thanks.
As always, my pleasure.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by