Non-numeric data type using fit function
9 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
Adam Danz
2019 年 8 月 9 日
編集済み: Adam Danz
2020 年 3 月 17 日
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
2019 年 8 月 13 日
If you want to take a big hammer approach, run
restoredefaultpath;rehash toolboxcache
This will reliably get rid of all of the extra stuff.
回答 (1 件)
Chris Angeloni
2019 年 8 月 13 日
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 件のコメント
Adam Danz
2019 年 8 月 13 日
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.
参考
カテゴリ
Help Center および File Exchange で Measurements and Statistics についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!