How to determine coefficients by fit for multiple series of data?
8 ビュー (過去 30 日間)
古いコメントを表示
Hey there,
I've searched for a while but did not find the right thing for my problem. I have several series of experiments with different amount of data, which might be described by an equation with 2 coefficents. The equation is:
D is a fixed value for each series of experiments, a and b are the coefficients I want to fit.
As an example x, y and D have the following values for three series of experiments (each row is one experiment):
x = [2,4,6,NaN,NaN; 2,4,6,8,10; 2,4,6,8,NaN];
y = [3,5,7,NaN,NaN; 4,8,11,25,32; 7,10,15,17,NaN];
D = [3;5;7];
Now I want to calculate the coefficients a and b by the fitting tool box, but the tool box throws just all values of y in and does not seperate the three cases with different value of D.
Is there a way to tell this the toolbox? or alternatively to calculate the coefficents by code?
Many thanks in advance for any help and best regards,
Benedikt
0 件のコメント
採用された回答
Torsten
2022 年 5 月 26 日
x = [2,4,6,NaN,NaN; 2,4,6,8,10; 2,4,6,8,NaN];
y = [3,5,7,NaN,NaN; 4,8,11,25,32; 7,10,15,17,NaN];
D = [3;5;7];
N = size(x, 1);
A = [];
b = [];
for K = 1:N
mask = ~(isnan(x(K,:)) | isnan(y(K,:)));
tx = x(K,mask).';
ty = y(K,mask).';
A = [A;D(K)*tx.^2,tx];
b = [b;ty];
end
ab = A\b
a = ab(1)
b = ab(2)
その他の回答 (1 件)
Walter Roberson
2022 年 5 月 26 日
x = [2,4,6,NaN,NaN; 2,4,6,8,10; 2,4,6,8,NaN];
y = [3,5,7,NaN,NaN; 4,8,11,25,32; 7,10,15,17,NaN];
D = [3;5;7];
N = size(x, 1);
ab = zeros(N, 2);
for K = 1 : N
mask = ~(isnan(x(K,:)) | isnan(y(K,:)));
tx = x(K,mask);
ty = y(K,mask);
ty2 = ty ./ tx; %now it is A*D*x + b
p = polyfit(tx(:), ty2(:), 1);
ab(K,1) = p(1)./D(K);
ab(K,2) = p(2);
end
ab
参考
カテゴリ
Help Center および File Exchange で Fit Postprocessing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!