Plot function generates markers but not lines
Show older comments
This is a least-squares problem, but I cannot get the "best fit line" to generate. I can plot markers however. Specifying '-', 'LineWidth' and others do not work. What am I doing wrong here? Software is R2015a
WS = [1912 82.2; 1920 73.6; 1924 72.4; 1928 71; 1932 66.8; 1936 65.9;
1948 66.3; 1952 68.8; 1956 62; 1960 61.2; 1964 59.5; 1968 60;
1972 58.59; 1976 55.65; 1980 54.79; 1984 55.92; 1988 54.93; 1992 54.65;
1996 54.50; 2000 53.83; 2004 53.84; 2008 53.12; 2012 53.00];
A = zeros(23,2); %shapes matrix dimensions for dataset
A(1:23,1) = ones; %design matrix ones
A(1:23,2) = WS(1:23,1); %fills design matrix with the independent variables
b = WS(1:23,2); %allocates parameters from dataset
x = (inv(A' * A)) * (A') * b;
for k = 1:23
y = (x(1,1) + x(2,1) * A(k,2));
plot(A(k,2),y)
hold on;
end
Accepted Answer
More Answers (0)
Categories
Find more on Surface and Mesh Plots 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!