When the data to fit correspond to nearly vertical ellipses, the resulting angle is sometimes around zero (corresponding to the wrong axis). A quick workaround is to change line 124 into: ``` if (par(2)>0) theta = 0.5 * atan2(par(2), par(1) - par(3)); else theta = 0.5 * atan2(-par(2), -par(1) + par(3)); end ```