0

我开始在 matlab 中使用 OOP。然而,在我的代码中使用 java 对象让我很头疼。具体来说,当我尝试运行 testClass.start() 时遇到了这个错误:

'char' 类型的输入参数的未定义函数 'SessionSettings'。

提到的函数存在于导入的 jar 中,如果它在 matlab 类之外运行,则代码运行良好。这是课程:

classdef testClass

 properties
     data
 end

 methods

      function obj = testClass()
         % class constructor
         javaaddpath /home/test/test-examples-1.5.3.jar;
         import test.examples.thingy.*;

      end


     function ret = start()
         % 
         settings = sessionSettings('configFilePath');
      end
 end

end
4

1 回答 1

1

Citing the documentation of import():

The import function only affects the import list of the function within which it is used. When invoked at the command prompt, import uses the import list for the MATLAB® command environment. If import is used in a script invoked from a function, it affects the import list of the function. If import is used in a script that is invoked from the command prompt, it affects the import list for the command environment.

The import list of a function is persistent across calls to that function and is only cleared when the function is cleared.

This means, that your method start() will see an empty import list.

于 2013-09-01T14:29:31.120 回答