Impact-Site-Verification: dbe48ff9-4514-40fe-8cc0-70131430799e

Search This Blog

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

Popular Posts

Followers