- #1
Sonolum
- 39
- 0
Okay, here's a problem that I've been struggling with for a few weeks.
I'm conducting a series of measurements, where I get two sets of data, i.e. one xdata value gives me two ydata values. I want to curve fit the two data sets to two different functions, F1 and F2, that depend on the same coefficients. By fitting ydata1 to F1 and ydata2 to F2, I hope to extract the coefficients that best fits to both data sets.
While I can fit to F1 or F2 separately, I can't seem to fit to both at once. The curve-fitting tool doesn't seem capable of this, and I've been playing around with lsqcurvefit but with no success. I haven't found any other functions that seem able to do what I want.
The thing is, I was able to set this fit up in a graphing program called Sigmaplot. In that program, I combined my data sets into one by copying one after the other, and then created another variable d which I defined as 0 for all the ydata1 points and 1 for all ydata2 points--
i.e. xdata=[xdata , xdata]; ydata=[ydata1 , ydata2]; d=[0,...,0,1,...,1]
Then I added an if statement in my fitting model, saying "if d==0, fit to F1, else fit to F2".
It works, but it's a pain because I have to manually enter the data and set up the fits and initial guess values by hand. I was hoping to use Matlab to set everything up automatically, but my attempts to do something similar haven't worked. Any suggestions would be greatly appreciated.
I'm conducting a series of measurements, where I get two sets of data, i.e. one xdata value gives me two ydata values. I want to curve fit the two data sets to two different functions, F1 and F2, that depend on the same coefficients. By fitting ydata1 to F1 and ydata2 to F2, I hope to extract the coefficients that best fits to both data sets.
While I can fit to F1 or F2 separately, I can't seem to fit to both at once. The curve-fitting tool doesn't seem capable of this, and I've been playing around with lsqcurvefit but with no success. I haven't found any other functions that seem able to do what I want.
The thing is, I was able to set this fit up in a graphing program called Sigmaplot. In that program, I combined my data sets into one by copying one after the other, and then created another variable d which I defined as 0 for all the ydata1 points and 1 for all ydata2 points--
i.e. xdata=[xdata , xdata]; ydata=[ydata1 , ydata2]; d=[0,...,0,1,...,1]
Then I added an if statement in my fitting model, saying "if d==0, fit to F1, else fit to F2".
It works, but it's a pain because I have to manually enter the data and set up the fits and initial guess values by hand. I was hoping to use Matlab to set everything up automatically, but my attempts to do something similar haven't worked. Any suggestions would be greatly appreciated.