%--------------------------------------------------------------------------
%Copyright 2016, Mengqiu Li

%The following code is licensed under a Creative Commons 
%Attribution-NonCommercial-ShareAlike 4.0 International Public License.

%Under the following terms:

%1) Attribution - You must give appropriate credit, provide a link to the 
%license, and indicate if changes were made. You may do so in any 
%reasonable manner, but not in any way that suggests the licensor 
%endorses you or your use. 

%Preferred method of attribution is citing or referring to the published 
%paper associated with this work: 
%Journal of the American Chemical Society, 2015, 137 (51), pp 16055–16063.

%2) NonCommercial - You may not use the material for commercial purposes.

%3) ShareAlike - If you remix, transform, or build upon the material, 
%you must distribute your contributions under the same license as the 
%original.

%4) No additional restrictions - You may not apply legal terms or 
%technological measures that legally restrict others from doing anything 
%the license permits.

%Under the above terms, you are free to:

%1) Share - copy and redistribute the material in any medium or format
%2) Adapt - remix, transform, and build upon the material

%The license in full: 
%   http://creativecommons.org/licenses/by-nc-sa/4.0/legalcode
%--------------------------------------------------------------------------

function Error=oneline_fitting(Parameters,X,Y,Length)
    [Coor1,Coor2]=size(X);
    if Coor2==1 && Coor1>1
    else
        error('   Unexpected X dimension, use a vertical vector');
    end
    [Coor1,Coor2]=size(Parameters);
    if min(Coor1,Coor2)==1 && max(Coor1,Coor2)==2
    else
        error('   Unexpected Parameter numbers');
    end
    A=Parameters(1);
    B=Parameters(2);
    X=X(1:Length);
    Y=Y(1:Length);
    Error=Y-(A.*X+B);
end