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.
댓글 수: 0
채택된 답변
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)
ymax=polyval(p,xmax)
writematrix([xmax,ymax],'filename.xlsx')
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!