error when trying to fit a custom function using cftool

1 回表示 (過去 30 日間)
Aviram Gelblum
Aviram Gelblum 2013 年 11 月 25 日
編集済み: Alex R. 2021 年 3 月 25 日
Hi, I'm trying to fit data to a custom exponential function a*exp(-b*x)+c. No fit is generated and I get the following error in the Results window: "Dimensions of matrices being concatenated are not consistent." I've tried generating clean, simple data to fit:
aa=2;
bb=0.5
cc=0.1;
xx=0:0.1:10;
yy=aa*exp(-bb*xx)+cc;
,cleaning all other variables (by opening a new instance of Matlab), and trying other custom functions, but nothing works...
It's worth mentioning that pre-defined fits (Polynomial, Exponential, etc.) can be generated.
I am using version R2012b.
  1 件のコメント
Elizabeth Jones
Elizabeth Jones 2015 年 6 月 3 日
I'm having the same problem now in R2014b. Did you ever find a solution?
Thanks! Elizabeth

サインインしてコメントする。

回答 (2 件)

Timothy Wiggin
Timothy Wiggin 2017 年 8 月 30 日
I had the same problem, I'm going to document how I fixed it in case it comes up for anyone else. Skipping ahead, try restoredefaultpath. I'm using Matlab R2017a.
The root of the problem is parsing the custom equation. Running this code:
xx = 1:20;
yy = 0.5 * exp(2*xx);
fit(xx' , yy' , 'a * exp(b * x)' )
Produces this output:
Error using horzcat
Dimensions of matrices being concatenated are not consistent.
Error in symvar>findrun (line 163)
d = diff([0 x 0]);
Error in symvar (line 26)
[b,e] = findrun(s==' ');
Error in fittype>iCreateCustomFittype (line 463)
variableNames = symvar( obj.expr );
Error in fittype>iCreateFittype (line 351)
obj = iCreateCustomFittype( obj, varargin{:} );
Error in fittype (line 328)
obj = iCreateFittype( obj, varargin{:} );
Error in fit>iFit (line 157)
model = fittype( fittypeobj, 'numindep', size( xdatain, 2 ) );
Error in fit (line 108)
[fitobj, goodness, output, convmsg] = iFit( xdatain, ydatain, fittypeobj, ...
symvar crashes because the vector s is a column vector, so the s==' ' expression produces a column vector, and the concatenation expects a row vector. The problem is somehow related to the Matlab path, because running:
restoredefaultpath
Fixes the problem.
  1 件のコメント
Alex R.
Alex R. 2021 年 3 月 25 日
編集済み: Alex R. 2021 年 3 月 25 日
Yes and no. Check whether you have a function called "vectorize" (which probably outputs a column vector) in one of your path included folders. Matlab will use that instead of the original "vectorize" function (which is not the most suitable name name if I was honest for what it's supposed to do).
I know this question is old, but I just commited that same mistake ...

サインインしてコメントする。


Salaheddin Hosseinzadeh
Salaheddin Hosseinzadeh 2015 年 6 月 3 日
編集済み: Salaheddin Hosseinzadeh 2015 年 6 月 3 日
Hi Guys,
Well done for providing the equations.
It worked fine for me, I attached an image
Or

カテゴリ

Help Center および File ExchangeGet Started with Curve Fitting Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by