function area = auc(x,y)

if length(x) ~= length(y)
    error('dimension mismatch');
end
if length(x) < 2
    area = 0;
    return
end

if size(x,2) > size(x,1)
    x = x';
end
if size(y,2) > size(y,1) 
    y = y';
end

% sort data
[x,i] = sort(x);
y = y(i);

xd   =  x(2:end) - x(1:end-1);
ym   = (y(2:end) + y(1:end-1))/2;
area = xd'*ym;
