![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/274479/image.jpeg)
I need matlab code to generate smooth curve for data set
조회 수: 1 (최근 30일)
이전 댓글 표시
x1 =[ 450 600 1500 3000 6000];
y1 =[ 1.8 1.0 0.43 0.3 0.22];
x2 =[ 750 1000 2500 5000 10000];
y2 =[ 3.6 2 0.86 0.6 0.44];
x3=[ 900 1200 3000 6000 12000];
y3 =[ 5.4 3.6 1.29 0.9 0.66];
plot(x1,y1);
hold on;
plot(x2,y2);
hold on;
plot(x3,y3);
title('operation current vs operation time');
xlabel('operation current(A)');
ylabel ('operation time(s)');
grid on;
i used curve fitting tool but cant plot all 3 curves in same grap
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/274429/image.png)
댓글 수: 0
채택된 답변
dpb
2020년 3월 1일
편집: dpb
2020년 3월 1일
There's a way to save the results of the fit session to the command window, but I always have to figure it out and it's more trouble than just doing the fit directly since you know the model you want...
X=[x1;x2;x3].'; % put the data into array by column
Y=[y1;y2;y3].';
f=arrayfun(@(i) fit(X(:,i),Y(:,i),'power2'),1:3,'uni',0); % fit all three pairs
figure,hAx=axes;hold on % make figure, prepare plot
hL=arrayfun(@(i) plot(f{i},'-',X(:,i),Y(:,i),'x'),1:3,'uni',0); % plot, save line handles
Yields
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/274479/image.jpeg)
Above saves the fits in the cell array f, to retrieve each just dereference with the curlies "{}"
>> whos f
Name Size Bytes Class Attributes
f 1x3 3147 cell
>> f{1}
ans =
General model Power2:
ans(x) = a*x^b+c
Coefficients (with 95% confidence bounds):
a = 3.791e+06 (-3.451e+07, 4.21e+07)
b = -2.412 (-4.065, -0.7593)
c = 0.2763 (0.06942, 0.4832)
>>
See the section on postprocessing linked to from the documentation for fit for all else can be done...
댓글 수: 0
추가 답변 (1개)
Thiago Henrique Gomes Lobato
2020년 3월 1일
if you look at the result you will see the fit function for each curve. In your actual image the "f(x)=a*x^b+c" with the coefficients below. You literally just need to plot this function with a given x interval. An example:
x1=400:6200;
y1 = a1*x1.^b1+c1; % Just copy the coefficient values from the result box for each curve
plot(x1,y1)
댓글 수: 1
dpb
2020년 3월 1일
But, there are only 4 significant digits in the display and one has to manually write the expression besides...not at all pleasant task.
There is a Generate Code option under the File menu that will write the above code (and a lot more that typically isn't needed) that can then use to get the actual coefficients in the model.
There's a Save Session function as well, but all one can do with it is to reload the data back into the tool.
참고 항목
카테고리
Help Center 및 File Exchange에서 Smoothing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!