Using Curve Fitter, computing Local Maximum (y) and corresponding (x) and export x y of fitted curve to external format (Excel)
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have a dataset: matlab_test_data.xlsx which I have uploaded to MATLAB (Home > Upload > matlab_test_data.xlsx).
I plotted the data using the following command:
%: Read the excel file using readtable function
rawTable = readtable('matlab_test_data.xlsx','Sheet','Sheet1');
x = rawTable.Days; %: get the excel column, Header1 (header name)
y = rawTable.Sucrose; %: get the excel column, Header2 (header name)
figure;
plot(x,y);
I then used the Curve Fitter (Apps > Curve Fitter > Select Data > Select Fitting Data)
Fitname: Trendline
X data: x
Y data: y
(Ignoring NaNs in data)
Polynomial Degree: 3
Robust: Off
Followed by Export > Export to Figure and Export to Workspace
How can I find the Local Maximum (y): 12.0799 and corresponding (x): 228.885 from the Fitted Curve (Trendline) in Figure 2 and extract (x,y) values of the Fitted Curve to Excel.
0 Kommentare
Akzeptierte Antwort
Matt J
am 31 Jul. 2022
Bearbeitet: Matt J
am 31 Jul. 2022
If all you're after is the local max, I would skip the curve fitting app and use polyfit.
keep=~(isnan(x)|isnan(y));
x=x(keep);
y=y(keep);
p=polyfit(x,y,3);
dp=polyder(p);
ddp=polyder(dp);
xs=roots(dp);
xs(abs(imag(xs))>1e-6)=0; %get rid of imaginary junk
xmax=xs(polyval(ddp,xs)<0)
ymax=polyval(p,xmax)
writematrix([xmax,ymax],'filename.xlsx')
6 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Spreadsheets finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!