Azzera filtri
Azzera filtri

Non-numeric data type using fit function

8 visualizzazioni (ultimi 30 giorni)
Chris Angeloni
Chris Angeloni il 7 Ago 2019
Modificato: Adam Danz il 17 Mar 2020
This is driving me crazy, I'm just trying to fit a gaussian curve to some data using Matlab's fit function (r2017a).
gaussEqn = 'a*exp(-((x-b)/c)^2)+d'
f = fit(x,y,gaussEqn);
But I get this error:
Error using fit>iFit (line 340)
Invalid data type. Second argument must be numeric or logical.
Yet my variables are both numeric...
whos x
Name Size Bytes Class Attributes
x 101x1 808 double
and
whos y
Name Size Bytes Class Attributes
y 101x1 808 double
Whyyyyy is this happening? At this point, I'll use a different function to fit my data, but it doesn't make any sense (and the internal fitting function iFit is not accessible)
_____________________________
A little extra detail:
The x and y variables are time and the mean of a matrix of interest; x for instance:
fs = 1000;
w = .1;
t = (-w:1/fs:0) * 1000; x = t';
The y variable is a bit more complicated, it is the mean of an estimated neural filter, which is computed by a different function that I wrote:
STA = genSTA(find(spkV),NSr(:,:,stimI),w,fs);
whos STA
Name Size Bytes Class Attributes
STA 25x101 20200 double
y = mean(STA,1);
whos y
Name Size Bytes Class Attributes
y 101x1 808 double
  12 Commenti
Adam Danz
Adam Danz il 9 Ago 2019
Modificato: Adam Danz il 17 Mar 2020
No need to make a copy of fit.m. Adding a break point does not require editing the code (see the link). Another advantage of adding a break point instead of copying the code is to ensure that fit.m is the exact function being invoked.
Anyway, when you executed the copied file, did it give you the same error? If xdatain and ydatain are both numeric, double, column vectors and you got that same error with those exact inputs, then I'm completely puzzled.
Sean de Wolski
Sean de Wolski il 13 Ago 2019
If you want to take a big hammer approach, run
restoredefaultpath;rehash toolboxcache
This will reliably get rid of all of the extra stuff.

Accedi per commentare.

Risposte (1)

Chris Angeloni
Chris Angeloni il 13 Ago 2019
I've long since been able to fit this data with another function, and I'm not going to put any more effort into trying to use fit.m. Based on the fact that loading my library creates the error, I'm gonna put it down to some conflict there... sorry guys, thanks for your help and comments!
  1 Commento
Adam Danz
Adam Danz il 13 Ago 2019
Just something to keep in mind; fit() is a common function and even if you remember to avoid using it, you could run into a toolbox or other function that uses fit() in which case, you're back to square one.
I think it's worth the time to figure out what program is interfering with your call to fit(). It could cause more problems down the lane.

Accedi per commentare.

Categorie

Scopri di più su Get Started with Curve Fitting Toolbox in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by