How to use lsqcurvefit on labelled contours for an image

4 views (last 30 days)
Hello all, Though I have done some reading, I still do not understand how to apply the lsqcurvefit to the labelled contour I plotted from the image based on the mat file attached. The program I used is included below. Please can someone help me out.Thanks.
Z = load('Ir_6716.mat');
flds = fieldnames(Z);% Fieldnames of data.
field = flds{1};% First field in data structure.
A = Z.(field);
B = -272.+A;% converts from kelvin to celsius
contour(flipud(B));
[C,h] = contour(interp2(flipud(B),'spline'));
clabel(C,h);

Accepted Answer

John D'Errico
John D'Errico on 13 Oct 2015
Edited: John D'Errico on 13 Oct 2015
Um, you can't. I.e., you cannot really use lsqcurvefit here, at least to any useful purpose on those contours. Why not?
- lsqcurvefit requires a model. You have not posed a model that has the fundamental shape of those contours. I seriously doubt whether you can come up with one either.
- lsqcurvefit requires a model of the essential form:
y = f(x,P)
here, P is a vector of the set of parameters to be estimated, and x is the independent variable. So in your case, you have no single valued function, y(x). You have a closed contour, so not a single valued function of an independent variable.
- For a given contour level from that plot, for example, at z = 25, there are MANY distinct, disjoint closed contours at that iso-level. You would need to build separate models for each of them.
At best, you MIGHT choose to extract the points for any given contour, then convert to polar coordinates. Now, build a model of the form
r = f(theta,P)
First though, you will still need to choose a model for that relationship.
Sorry, but whoever told you that lsqcurvefit would work here was probably thinking of a simpler case. (Or perhaps they simply have no concept of what lsqcurvefit does or how to use it.)
For example, suppose I did this:
[x,y] = meshgrid(0:.01:1);
z = exp(x.*y);
contour(z)
Now, I could extract any of those disjoint contours. Then I could come up with an intelligent model for that contour. In this case, I know it to be of the form
y = k./x
where k is an unknown constant. lsqcurvefit would have no problem solving this.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!