Linear Regression Model (Data points inserted using mouse pointer) | MATLAB


Prerequisite:



clc
clear all
close all
a=input('Enter , how many times you want to run the same code:');
x=[];
y=[];
h=0;
for i=1:a
    axis([-10 10 -10 10]);
    [m,n]=ginput(1);
    x=[x m];
    y=[y n];
    plot(x,y,'o');
    if(length(x)>2)
    delete(h);
    end
    axis([-10 10 -10 10]);
    if(length(x)>1)
    a=[];
for i=1:length(x)
    a=[a ; x(i) 1];
end
 c =a\y';
yR = c(1)*x + c(2); % the fitted line
hold on;
h=plot(x,yR,'k','linewidth',3);
axis([-10 10 -10 10]);
    end
end


No comments

'; (function() { var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); })();