Using Curve Fitter, computing Local Maximum (y) and corresponding (x) and export x y of fitted curve to external format (Excel)
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hansraj
el 31 de Jul. de 2022
Comentada: Hansraj
el 31 de Jul. de 2022
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 comentarios
Respuesta aceptada
Matt J
el 31 de Jul. de 2022
Editada: Matt J
el 31 de Jul. de 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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Spreadsheets en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!