Check for missing argument or incorrect argument data type in call to function 'fit' - using two 1x15 double arrays as an input argument

50 次查看(过去 30 天)
I am trying to fit to arrays and I get the error 'Check for missing argument or incorrect argument data type in call to function 'fit''.
The code I use:
clear all
close all
clc
year=[1991,1994,1995,1996,1997,2000,2001:1:2004,2007,2008,2016,2021,2024]
capacity=[ 0.4,0.5,0.5,0.7,0.6,2,2,2,3,4.5,5,5,10,12,14]
matrix=[year;capacity]
f=fit(year,capacity,'poly2')
Can anyone tell me what is wrong with this code?
  3 个评论
Laura Stokbro
Laura Stokbro 2020-9-7
Okay, Thank you for the answer!
The thing is that I would like to try also using an exponential fit to see what is more accurate.
I do not understand what is wrong with inputting two arrays into the 'fit' function?
Laura Stokbro
Laura Stokbro 2020-9-7
Thanks.
Though Ill have to predict future scenarios, so if the development is exponential it will grow faster than predictions using the polynomial fit. So I'd really like to be able to fit the points exponentially as well. Can you help me with that?

请先登录,再进行评论。

采纳的回答

Bernard Beitz
Bernard Beitz 2020-9-30
编辑:Bernard Beitz 2020-9-30
Summary: Don't forget to install all needed toolboxes (curve fitting toolbox) after installing a newer version of matlab.
The Problem sounds like you have the statistics toolbox installed but not the curve fitting toolbox. Try typing
which fit -all
to validate. The command will show every function called 'fit' that matlab knows about The correct feedback is similar to this:
>> which fit -all
/MATLAB/toolbox/curvefit/curvefit/fit.m
/MATLAB/toolbox/stats/stats/@gmdistribution/fit.m % gmdistribution method
If fit from curve fitting toolbox is missing, matlab will call the stats toolbox function which has different input types. If both are installed, matlab will determine by the type of the input paramters which function to call, so this won't be a problem.

更多回答(2 个)

Alan Stevens
Alan Stevens 2020-9-7
Here's a way of fitting a simple exponential curve. However, you definitely don't want to use it to extrapolate!
year=[1991,1994,1995,1996,1997,2000,2001:1:2004,2007,2008,2016,2021,2024];
capacity=[ 0.4,0.5,0.5,0.7,0.6,2,2,2,3,4.5,5,5,10,12,14];
% Exponential fit by taking logs first
% capacity = a*exp(b*year)
% ln(capacity) = ln(a) + b*year
lcap = log(capacity);
c = polyfit(year,lcap,1);
a = exp(c(2)); b = c(1);
capfit = @(t) a*exp(b*t);
t = 1991:2024;
plot(year,capacity,'o',t,capfit(t))
grid
xlabel('year'),ylabel('capacity')
legend('data','exponential fit')

JP
JP 2020-9-11
I get the same error even with the examples from the Help Center: https://de.mathworks.com/help/curvefit/fit.html#bto2vuv-1-fitType
I tried for example this:
load census;
f=fit(cdate,pop,'poly1');
plot(f,cdate,pop)
Is there a problem with fit function in Matlab 2020a?
Best

类别

Help CenterFile Exchange 中查找有关 Get Started with Curve Fitting Toolbox 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by