필터 지우기
필터 지우기

How to extract multiple cfit or fit values into one table

조회 수: 16 (최근 30일)
B
B 2020년 12월 16일
댓글: B 2020년 12월 17일
Dear all,
So I have a 31x 19 matrix data and I had to fit the first column data (31X1) and the rest of all the 18 columns (31x18).
I wrote a simple if function to do this but my challenge now is about how to extract each fit coefficients (f) including confidence intervals into one Table. I already used coeffvalues but only returns my last f as the ans
Mycode is a follows
r = randi([0, 100], 31,19)
b = (r(:,1));b2=b(:,2:end);
for i= 1:size(b2,2)
% [f, gof_info] = fit(b1,b(:,2),'power1');
f{i}= fit(b, b2(:,i),'power1')
%f_values= coeffvalues(f{i})
end
Your help will be deeply appreciated.
Thanks
E

채택된 답변

Isabelle Levy
Isabelle Levy 2020년 12월 17일
Hi E,
I understand you’re having trouble condensing data that you’ve generated using the fit function. I noticed a few potential typos in your code. See my comments in green:
r = randi([0, 100], 31,19) %Power functions are unable to fit to data where X may contain nonpositive values; change the range from [0-100] to [1-100]
b = (r(:,1));
b2=b(:,2:end); %I think you meant to write b2 = r(:,2:end)
for i= 1:size(b2,2)
f{i}= fit(b, b2(:,i),'power1') %The appropriate syntax for a fit function would be f = fit(b, b2(:,i),'power1')
end
In addition to the coeffvalues function, you will also want to use the confint function to obtain the confidence levels associated with each result. With that being said, consider the revised following revised code (see comment below). The first iteration of the for loop populates the first two columns of an array with the corresponding coefficients and confidence intervals determined by fitting the data. The for loop executes a total of 18 times, so the result is a 3-by-36 array where the first row stores the coefficients and the second two rows store the corresponding lower and upper bounds. The array2table function then converts the array to a table.
  댓글 수: 2
Isabelle Levy
Isabelle Levy 2020년 12월 17일
r = randi([1,100],31,19);
b = (r(:,1));
b2 = r(:,2:end);
array1 = zeros(3,2*size(b2,2));
col=1;
for i= 1:size(b2,2)
f = fit(b, b2(:,i),'power1');
array1(1,col:col+1) = coeffvalues(f);
array1(2:3,col:col+1) = confint(f);
col=col+2;
end
table = array2table(output,'RowNames',{'Coefficients','Lower Bound','Upper Bound'})
I hope this helps!
-Isabelle
B
B 2020년 12월 17일
Good answer, I guess for the start:)

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Fit Postprocessing에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by