Package function not allowed in fittype?

15 ビュー (過去 30 日間)
Steve Van Hooser
Steve Van Hooser 2020 年 9 月 27 日
コメント済み: Steve Van Hooser 2025 年 7 月 11 日 11:11
I have a function called 'linepowerthreshold' that I use to fit a function. I recently made it into a package and put it in the directory:
+vlt/+fit/linepowerthreshold.m
While the following works great, when linepowerthreshold.m was just an m file not inside a package:
ft = fittype('linepowerthreshold(x,a,0,b,1);','options',s);
The following contruction fails in Matlab 2020a (MacOS, Mojave):
ft = fittype('vlt.fit.linepowerthreshold(x,a,0,b,1);','options',s);
Error using fittype/testCustomModelEvaluation (line 12)
Expression vlt.fit.linepowerthreshold(x,a,0,b,1); is not a valid MATLAB expression, has non-scalar coefficients, or cannot be evaluated:
Error in fittype expression ==> vlt.fit.linepowerthreshold(x,a,0,b,1);
??? Dot indexing is not supported for variables of this type.
This is a workaround but it seems like passing a package-based function should work, too, yes?
ft = fittype(@(a,b,x) vlt.fit.linepowerthreshold(x,a,0,b,1),'options',s);
The function when called alone works fine, and is byte-by-byte the same as the version that is not in a package (except for the documentation).
Help?

採用された回答

Jayanti
Jayanti 2025 年 7 月 11 日 5:53
Hi Steve,
This behavior occurs due to how "fittype" handles inputs. The documentation states that any ".m file" or anonymous function can be used, this applies to functions that are accessible directly in the MATLAB path and does not support dot-indexed package names in expression strings.
You can also refer to the below documentation for more information:
  1 件のコメント
Steve Van Hooser
Steve Van Hooser 2025 年 7 月 11 日 11:11
Thank you!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLinear and Nonlinear Regression についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by