Matlab 从自定义函数定义fittype对象
我试图从函数中定义一个Matlab 从自定义函数定义fittype对象,matlab,function,Matlab,Function,我试图从函数中定义一个fittype对象(写在一个单独的.m文件中) 其中,c1,c2,c3,c4,c5,c6为可变拟合参数,p为常数结构: ft = fittype(@(c1,c2,c3,c4,c5,c6,x) fun(x,c1,c2,c3,c4,c5,c6,P), 'independent', {'x'}, 'dependent', {'y'}); 但会出现以下错误: Error using fittype>iTestCustomModelEvaluation (line 730)
fittype
对象(写在一个单独的.m文件中)
其中,c1
,c2
,c3
,c4
,c5
,c6
为可变拟合参数,p
为常数结构:
ft = fittype(@(c1,c2,c3,c4,c5,c6,x) fun(x,c1,c2,c3,c4,c5,c6,P), 'independent', {'x'}, 'dependent', {'y'});
但会出现以下错误:
Error using fittype>iTestCustomModelEvaluation (line 730)
Custom equations must produce an output vector, matrix, or array that is the same size and shape as the input data.
This custom equation fails to meet that requirement:
Error in fittype>iCreateFittype (line 367)
iTestCustomModelEvaluation( obj );
Error in fittype (line 324)
obj = iCreateFittype( obj, varargin{:} );
该函数可以很好地生成相同大小的
x
和y
数据,因此我不知道定义fittype失败的原因。Struct p不需要作为问题相关参数添加。解决这个问题的方法是确保输入/输出向量中的列大小相同。Fit()仅适用于列。我现在知道了!谢谢你的建议 我不知道如果不看到fun
的内部结构(或者一个演示相同问题的示例),我们如何能提供帮助。愚蠢的问题,但如果将'x'/'y'
添加为字符串而不是单元格,它会说同样的话吗?您是否绝对确定fun
返回与输入x
相同的形状,而不考虑其尺寸?另外,我会尝试添加P
作为一个问题相关参数,但同样,如果这有帮助,我会感到惊讶。如何将数据列转换为行,或者反之亦然?fit()可能很有趣。
Error using fittype>iTestCustomModelEvaluation (line 730)
Custom equations must produce an output vector, matrix, or array that is the same size and shape as the input data.
This custom equation fails to meet that requirement:
Error in fittype>iCreateFittype (line 367)
iTestCustomModelEvaluation( obj );
Error in fittype (line 324)
obj = iCreateFittype( obj, varargin{:} );