MATLAB: Finding Unknown X from Known Y with cftool

curve fittingCurve Fitting Toolbox

Hello all,
Very very new matlab user here. I seem to be able to muddle my way around the software and I have the curve fit toolbox. I have gone through the help activities and seem to be stumped on what to do after I have fit a curve to my data. I do see that an equation for my fit is generated in the results area, but how do I use this in an automated fashion? I was hoping that after generating fit I could somehow enter a Y axis value and have matlab find me the answer (X), withouth having to do it manually. I can't seem to get any of the post processing formulas to give me data that even remoting makes sense. Thanks for your help!

Best Answer

You realize that some fitted functions are not monotone, so there may be multiple x values that evaluate to the same y value. But forgetting that, you could try something like this, using Sean's notation:
for j=1:length(y2)
x2(j) = fzero(@(t)fittedmodel(t)-y2(j),[min(x),max(x)]);
end
This loops over a vector of given y2 values, and tries to locate an input value at which the fittedmodel predicts each given y2 value. This will work only if the given y2 values are between the function values at the two extreme x values.