Non-numeric data type using fit function

8 views (last 30 days)
Chris Angeloni
Chris Angeloni on 7 Aug 2019
Edited: Adam Danz on 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 Comments
Adam Danz
Adam Danz on 9 Aug 2019
Edited: Adam Danz on 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 on 13 Aug 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.

Sign in to comment.

Answers (1)

Chris Angeloni
Chris Angeloni on 13 Aug 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 Comment
Adam Danz
Adam Danz on 13 Aug 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.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!