Finding Unknown X from Known Y with cftool

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!

댓글 수: 1

the cyclist
the cyclist 2012년 5월 25일
It would be helpful if you gave more details about exactly which MATLAB functions you have used to generate the fit. If you can provide a small code sample as an example, that's the best.

댓글을 달려면 로그인하십시오.

 채택된 답변

Tom Lane
Tom Lane 2012년 5월 25일

0 개 추천

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.

댓글 수: 4

Andrew Wheeler
Andrew Wheeler 2012년 5월 25일
AWESOME! This works...
Thank you so much!
Andrew Wheeler
Andrew Wheeler 2012년 5월 30일
So I am working on real data now. The code provided by Tom works great with any of the preset curve functions in cftool. Now I am using a custom equation: 4PL logit log : ((A-D)/(1+((x/C)^B))) + D
After I set the lower and upper bounds I get a nice fit. I then try and use Tom's code to find the unknowns (or validate how good my curve fit was). The code returns with
Exiting fzero: aborting search for an interval containing a sign change
because NaN or Inf function value encountered during search.
(Function value at -3.64 is NaN.)
Check function or try again with a different starting value.
My data is: x = 13,25,100,1000,10000
y = 789,1775,5881,25487,34781
y2 = 789,1775,5881,25487,34781
lower bounds on A=0, B=0, C=100,D=10000
R2=1
Any ideas? The website readerfit.com does this very easily, but I want to get matlab to do it so I can process a lot of data at once.
Thanks for any help!
Tom Lane
Tom Lane 2012년 5월 30일
There was a typo in my answer, which I just corrected. You need brackets around [min(x),max(x)]. In addition, if your fit doesn't span the y2 values you provide, you may need to expand the x interval beyond the min/max of the input data. (By the way, I found I needed B<0 to fit your data well.)
Andrew Wheeler
Andrew Wheeler 2012년 5월 30일
This is awesome! Thanks again. I didn't even think about adding brackets. With my orginal settings only the first point (y=789) returns an error. It is probably like you said, outside of the fit. I'll try it with b<0 and see how it goes.
Can't thank you enough!
Andy

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Sean de Wolski
Sean de Wolski 2012년 5월 25일

0 개 추천

First: This a good question. +1.
After you're done fitting with the CFTOOL go to "fit">"Save to Workspace". This will then generate an object called fittedmodel (or whatever you choose to name it in the dialog). To use this on other data:
y2 = fittedmodel(x2);
More Small example:
x = 1:10;
y = (1:10)+randn(1,10)+3; %noisy y (nominally: y = x+3)
cftool(x,y)
%Make model and save fitted model
%Now run:
x2 = 10:20;
y2 = fittedmodel(x2);

댓글 수: 4

Andrew Wheeler
Andrew Wheeler 2012년 5월 25일
Hi Sean,
okay...so to make things as easy as possible. here is my data:
simple linear. x's = 1,2,3,4,5. y's= 10,20,30,40,50
I go into cftool and use custom equation (m*x+b) and get perfect r2 etc.
save to workspace.
Then...if I use x=fittedmodel(10) I get an answer of x=100
If I use y2 = fittedmodel (x2) it doesn't work at all
If I use y=fittedmodel(x) I get an answer of y= 1000. I want to solve for x using the fit!
Sorry for the novice questions. I must be missing something basic to how matlab works?
My real data is much more complex than this, but I thought a linear fit would be the easiest to check if I am doing things right.
-
the cyclist: I have tried all of the functions listed in the help section of the Cruve fit toolbox under Interpolation and Fit Postprocessing. Some times I get really huge numbers for an answer (way way outside the range of my curve).
All I want to do is use the curve fit data to calculate an unknown x value when I know the Y (without having to calculate manually).
Thanks for your help.
Sean de Wolski
Sean de Wolski 2012년 5월 25일
see addendum
Andrew Wheeler
Andrew Wheeler 2012년 5월 25일
It seems your example takes known x axis data and gives the coresponding y axis data. I need it the other way around. I know the Y axis value and need to calculate specific X axis data based on the curve.
for example, based on my original (easy data) a y axis value of 25 should give a calculated x value of 2.5, instead when I run your equation y2=fittedmodel(x2) it returns 250. However if I input a value of 6 for x2 then the formula correctly returns a y2 value of 60 (the calculated y axis value when x=6.
I want to find calculated x axis. I have the y axis data. In the example above. What would x be if y = 35. Of course this is simple equation, but I want Matlab to do it for me so when my real data is used (much much more complex) I don't have to do it manually.
Sean de Wolski
Sean de Wolski 2012년 5월 25일
Maybe I'm underestimating this, but why don't you just switch the inputs?

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by