nass-micro-station-measurem.../static-spindle/Macros_ttt_spindle/myFit.m

36 lines
898 B
Matlab

function [Y] = myFit(x, y, start, End, file)
W = (y-y(1)) - (y(End-start)-y(1))/(x(End - start))*x;
A = [x ones(size(x))]\y;
a = A(1); b = A(2);
Y = y - (a*x + b);
fig = newFigure(16,20);
subplot(2,1,1);
plot (x, y, 'r');
grid on
xlabel ('Time (sec)', 'interpreter', 'latex')
ylabel ('Straightness $( \mu{} \mathrm{m})$', 'interpreter', 'latex')
title ('Straightness-Raw', 'interpreter', 'latex')
subplot(2,1,2);
plot (x, Y, 'color',[0 0.5 0]);
grid on
%ylim([-10 14]);
xlabel ('Time (sec)', 'interpreter', 'latex')
ylabel ('Straightness $( \mu{} \mathrm{m})$', 'interpreter', 'latex')
title ('Straightness-Corrected', 'interpreter', 'latex')
m= max(Y) - min(Y);
text(1,10, 'max - min =', 'interpreter', 'latex')
text(1,6, [num2str(m) ' $\mu{} \mathrm{m}$'], 'interpreter', 'latex')
string = { file };
Newstring = {string{1}(1:end-4)} ;
p= char(Newstring);
exportFigure(fig,p, 'png');
end