Fitting two data sets with one curve

Hi folks,
I have two data sets, S = (Vs, Is) and P = (Vp, Ip) which I would like to model using a function with one common parameter and one that depends on the dataset, like: f(V,param) = a(param)*V^b, and para = p or s.
Is there some easy wasy to do this using CFT?
Best, Robert

 채택된 답변

the cyclist
the cyclist 2011년 12월 28일

0 개 추천

I don't really have any experience with the curve fitting tool, but the way to do this in general is to use a dummy variable (value = 0 or 1) that you set to 0 for one set of data, and 1 for the other set of data. You could use nlinfit() from the Statistics Toolbox to do this kind of fit.
I could probably cobble together a simple example if it is not clear what I mean.
EDIT: Added example below in response to later comment.
% Some pretend explanatory data
x = [1:10,1:10]'; % Some explanatory variable (e.g. values 1-10 for each group might be grades 1-10)
g = [zeros(1,10),ones(1,10)]'; % Dummy variable, indicating two different groups (e.g. 0=boys,1=girls)
% Some pretend output or "response" variable
% I deliberately create it like this, to be well fit by a model,
% so that you can see what is going on
A = 3; % Fixed level
B = 4; % Coefficient of dependency on x
C = 10; % Effect of the group
R = 2; % Some randomness so we don't get a perfect fit
% The response
y = A + B*x + C*g + R*randn(20,1);
% Fit a linear model to the data
[b,bint,r,rint,stats] = regress(y,[ones(20,1) x g]); % Need to include a column of ones. (See "doc regress")
% Calculate the fitted value of y, for each value of x,g
yFit = [ones(20,1) x g] * b;
% Display a comparision between data and fitted values
figure
plot(x,y,'bo',x,yFit,'rx')
legend({'Data','Fitted value'},'Location','NorthWest')

댓글 수: 1

Robert Rehammar
Robert Rehammar 2011년 12월 28일
Thanks! This was exactly what I was looking for, no need for an example.

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

추가 답변 (1개)

Navneet Viswan
Navneet Viswan 2012년 3월 7일

0 개 추천

@ the cyclist Hey, even i'm struck in the same problem. Seems your solution will work for me. Can you help me out with an example to understand it better?
VJ

Community Treasure Hunt

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

Start Hunting!

Translated by