using 'fit' to add a trend line to series of scatter points
Show older comments
Hi there,
I am trying to add a trendline to a series of scatter points that represent geographic locations and have an estimate of the goodness of fit.
Here is a simplified version of my data- please can someone help me pin point why/ where it is going wrong. This is the output I get and as you can see this cannot be right from looking at the values on my y-axis
f =
Linear model Poly1:
f(x) = p1*x + p2
Coefficients (with 95% confidence bounds):
p1 = 0.1116 (-0.04946, 0.2726)
p2 = 37.37 (32.47, 42.27)
clear all
close all
lat = [30.4056270000000;30.3991500000000;30.4000740000000;30.4046990000000;30.4102510000000;30.4093280000000;30.3889660000000;30.3982300000000;30.4074760000000;30.4195050000000;30.4139500000000;30.4120980000000;30.4083980000000;30.3936010000000;30.3926810000000]
lon= [40.7602680000000;40.7609660000000;40.7616710000000;40.7623780000000;40.7623830000000;40.7602710000000;40.7644750000000;40.7574480000000;40.7616770000000;40.7609820000000;40.7637930000000;40.7651980000000;40.7637880000000;40.7595540000000;40.7560360000000]
h=[30.3 30.45 40.72 40.8];
lat_lon_proportions(h) %function taken from Jonathen Sullivan - available from https://uk.mathworks.com/matlabcentral/fileexchange/32462-correctly-proportion-a-lat-lon-plot
% plot(lat,lon,'k.')
x=lon
y=lat
hold on
f=fit(y,x,'poly1')
plot(f,y,x)

Accepted Answer
More Answers (0)
Categories
Find more on Exploration and Visualization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!