MATLAB Answers

problem with fit function for data

조회 수: 10(최근 30일)
Nirvan Hashemian
Nirvan Hashemian 2021년 9월 22일
댓글: Star Strider 2021년 9월 24일 10:47
I have a problem with getting the fit function to work
clear; clc;
E = [416.861, 818.7, 1097.3, 1293.54,1507.4];
e = flip([1.7e-1, 1.6870e-1, 2.045e-1, 1.956e-1, 6.255e-1]);
f = fit(E,e,'exp1');
plot(f,E,e,'rx','markersize',8)
grid on
this gives me this error:
Error in fit (line 116)
[fitobj, goodness, output, convmsg] = iFit( xdatain, ydatain, fittypeobj, ...
Error in Untitled2 (line 6)
f = fit(E,e,'exp1');
No idea why this happens, and I do have ethe curve fitting toolbox installed.

채택된 답변

Star Strider
Star Strider 2021년 9월 22일
The fit function requires column vector arguments. Force that sith the ‘(:)’ subscript noitation.
E = [416.861, 818.7, 1097.3, 1293.54,1507.4];
e = flip([1.7e-1, 1.6870e-1, 2.045e-1, 1.956e-1, 6.255e-1]);
f = fit(E(:),e(:),'exp1');
hp = plot(f,E,e,'rx');
hp(1).MarkerSize = 8;
grid on
The other problem is that the 'MarkerSize' is ambiguous here, since both the data and fit are plotted, so use that as a separate assignment and reference the appropriate line object.
.
  댓글 수: 2
Star Strider
Star Strider 2021년 9월 24일 10:47
As always, my pleasure!
.

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

추가 답변(0개)

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by