Using Curve Fitter, computing Local Maximum (y) and corresponding (x) and export x y of fitted curve to external format (Excel)

조회 수: 4 (최근 30일)
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.

채택된 답변

Matt J
Matt J 2022년 7월 31일
편집: Matt J 2022년 7월 31일
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)
xmax = 229.1196
ymax=polyval(p,xmax)
ymax = 12.0800
writematrix([xmax,ymax],'filename.xlsx')
  댓글 수: 6
Hansraj
Hansraj 2022년 7월 31일
I'm having trouble with the below command and recommended xlwrite and writematrix to export the (x,y) data to excel format.
x=get(gco,'Xdata')
y=get(gco,'Ydata')
Hansraj
Hansraj 2022년 7월 31일
To those who may be interested, please read
x=get(gco,'Xdata')
y=get(gco,'Ydata')
Followed by:
writematrix([x(:), y(:)],'filename3.xlsx')

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

추가 답변 (0개)

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by