MATLAB: Best fit of ellipse equation to given data

best fitellipseequation solvingfit data to ellipseleast squaresMATLAB and Simulink Student Suite

Hello everyone,
For the given ellipse equation denoted as follows:
with additional parameters of mc and PIc to include a rotation of the ellipse:
I need to find
  1. a and b (semi-major and semi-minor axes),
  2. y0 and x0 (center coordinates), and
  3. theta(rotation angle)
to have best fitted ellipse into my data which is give in the form of PI = f(m) with around 5-8 test points per dataset.
Given the fact that my data has various shapes I do not expect the ellipse to be very precise, but still I would like the best I can get out of this method. I have tried to achieve that with Curve Fitting app, using Custom Equation option, but the equation I have put into it was too complex (some errors occurred).
Can you please advice, what would be the most convenient way to achieve my goal?
Kind Regards