Check for missing argument or incorrect argument data type in call to function 'fit' - using two 1x15 double arrays as an input argument
Show older comments
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 Comments
KSSV
on 7 Sep 2020
You can use polyfit instead.
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]
% f=fit(year,capacity,'poly2')
p = polyfit(year,capacity,2)
plot(year, capacity,'*r')
hold on
plot(year,polyval(p,year))
Laura Stokbro
on 7 Sep 2020
Laura Stokbro
on 7 Sep 2020
Accepted Answer
More Answers (2)
Alan Stevens
on 7 Sep 2020
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
on 11 Sep 2020
0 votes
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
2 Comments
Ludovicamaria Amedeo
on 22 Nov 2020
you have to download the "curve fitting" toolbox :)
JP
on 22 Nov 2020
thank you,
I luckily found it out by myself shortly after posting this. Strange that for such a basic method you need a toolbox...
Categories
Find more on Linear and Nonlinear Regression in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!