0

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)


Requested edit:

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   
5
  • could you provide the whole code? Perhaps there is something missing between the variable declarations and the use of the fit function.
    – Thales
    Aug 6, 2019 at 20:00
  • Did you tried to copy MATLAB example on the help?
    – Thales
    Aug 6, 2019 at 20:02
  • The example works fine. I could post the rest of the code, but there is quite a lot of preprocessing going into the two variables, I will edit to be more clear what steps happen in between
    – Chris
    Aug 7, 2019 at 20:16
  • could you save and upload the x and y variables?
    – Thales
    Aug 8, 2019 at 20:23
  • I also posted this question on Matlab Answers forums, here is a link, and I will try to post the answer here if we get anywhere... mathworks.com/matlabcentral/answers/…
    – Chris
    Aug 9, 2019 at 16:31

1 Answer 1

0

In the end, this issue was happening because somewhere in my library there is a toolbox with a modified fit function that was causing the error

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .