![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/274479/image.jpeg)
I need matlab code to generate smooth curve for data set
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Akzeptierte Antwort
dpb
am 1 Mär. 2020
Bearbeitet: dpb
am 1 Mär. 2020
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 Kommentare
Weitere Antworten (1)
Thiago Henrique Gomes Lobato
am 1 Mär. 2020
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 Kommentar
dpb
am 1 Mär. 2020
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.
Siehe auch
Kategorien
Mehr zu Smoothing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!