Commit b5979863 authored by Pierre Cazenave's avatar Pierre Cazenave

Add slightly more robust input variable checks

parent f56b39db
...@@ -9,7 +9,7 @@ function [x0,y0,a] = centroid(x,y) ...@@ -9,7 +9,7 @@ function [x0,y0,a] = centroid(x,y)
[m1,n1] = size(x); [m2,n2] = size(y); [m1,n1] = size(x); [m2,n2] = size(y);
n = max(m1,n1); n = max(m1,n1);
if [m1,n1] ~= [m2,n2] || min(m1,n1) ~= 1 || n <= 1 if (m1 ~= m2 && n1 ~= n2) || min(m1,n1) ~= 1 || n <= 1
error('Args must be equal-sized non-scalar vectors') error('Args must be equal-sized non-scalar vectors')
end end
x = x(:); y = y(:); x = x(:); y = y(:);
...@@ -17,4 +17,4 @@ x2 = [x(2:n);x(1)]; ...@@ -17,4 +17,4 @@ x2 = [x(2:n);x(1)];
y2 = [y(2:n);y(1)]; y2 = [y(2:n);y(1)];
a = 1/2*sum (x.*y2-x2.*y); a = 1/2*sum (x.*y2-x2.*y);
x0 = 1/6*sum((x.*y2-x2.*y).*(x+x2))/a; x0 = 1/6*sum((x.*y2-x2.*y).*(x+x2))/a;
y0 = 1/6*sum((x.*y2-x2.*y).*(y+y2))/a; y0 = 1/6*sum((x.*y2-x2.*y).*(y+y2))/a;
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment