clear; close all; clc
 format long

sen_f10lbs = [0 1 2 3.5 5 8 11 14 18 22 26 30 36 40 44]; %força sensores de 10 lbf

sen2adc = [51 69 85 110 134 182 231 278 342 408 473 537 637 701 770]; %valor adc sensor 2

sen4adc = [3 13 28 50 72 117 162 209 268 328 389 453 547 610 672]; %valor adc sensor 4

senf5lbs = [0 0.5 1 1.5 2.5 4 5 6 8 10 13 16 19 22 24 ]; %força sensores de 5lbf

sen3adc = [70 91 110 130 168 231 271 312 391 470 587 710 830 948 1014]; %valores adc sensor 3

x= sen2adc; y= sen_f10lbs;

%x= sen4adc; y= sen_f10lbs;

%x=sen3adc; y=senf5lbs;

[mb,erro]=polyfit(x,y,1)

X=linspace(0,1100);

Y= mb(1)*X + mb(2);

plot(x,y,'*',X,Y,'-r')
xlabel('Analogue voltage')
ylabel('Force [N]')

%   x = 0:0.1:10;
%   y = 2.*x + 1 + randn(size(x));

   p = polyfit(x,y,1);
   f = polyval(p,x);
   [r2,rmse] = rsquare(y,f);
   figure; plot(x,y,'b-');
   hold on; plot(x,f,'r-');
   title(strcat(['R2 = ' num2str(r2) '; RMSE = ' num2str(rmse)]))
