problem with anonymous function in executable

1 回表示 (過去 30 日間)
Emre Kocatulum
Emre Kocatulum 2015 年 7 月 16 日
コメント済み: Muthu Annamalai 2015 年 7 月 17 日
I have a three files that work perfectly. However when I compile them matlab behaves as if I didn't include one of the files even though it is included in the deployment.
function testMain
kuzu = zeros(5,1);
anonymousFunction = testClass.anonymousFunction;
kuzu2 = anonymousFunction(kuzu)
end
classdef testClass
properties (Constant)
anonymousFunction = @(x) replaceZeroWithNaN2(x)
end
end
function output = replaceZeroWithNaN2(input)
input(input==0) = NaN;
output = input;
end
All the files are in the same directory. After compilation I get the following error:
Undefined function 'replaceZeroWithNaN2' for input arguments of type 'double'

採用された回答

Muthu Annamalai
Muthu Annamalai 2015 年 7 月 16 日
While I don't have a explanation of why you are seeing this error, I have a suggestion to rewrite your code.
Generally function handles are useful in context of algorithms | | , i.e. sort algorithm needs a comparator etc, integration algorithm needs a value of function at a point (x,y) etc.
For all other purposes I recommend using static methods : see examples of static methods .
Can you rewrite your code to make ' replaceZeroWithNaN2 ' a static method of class ' testClass ' and see what happens? I assume the codegenerator will have a easier time resolving that symbol.
Goodluck.
  2 件のコメント
Emre Kocatulum
Emre Kocatulum 2015 年 7 月 17 日
Using static methods seem to work. So is there some instability in the way code generator handles anonymous functions?
Muthu Annamalai
Muthu Annamalai 2015 年 7 月 17 日
Glad to know this worked for you Emre.
I encourage you to still file a customer report with Mathworks technical support.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeJava Package Integration についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by