How to import for the whole class in matlab?

I have a class that uses other classes from another package in several functions. To do this, I need to import the package into each function:

classdef foo properties bar end methods function self = foo() foo.bar = 1; end function fun1(foo) import pkg.FooClass; val = pkg.FooClass(foo.bar); end function fun2(foo) import pkg.FooClass; val = FooClass.fun(foo.bar); end end end 

Is there a way to import packages for the whole class? I am looking for something similar to other languages:

 classdef foo import pkg.FooClass; properties bar end methods function self = foo() foo.bar = 1; end function fun1(foo) val = pkg.FooClass(foo.bar); end function fun2(foo) val = FooClass.fun(foo.bar); end end end 
+4
source share
1 answer

Unfortunately, the doc page states that:

The import function only affects the import list of the function within which it is used.

Therefore, you must either provide a fully qualified name worldwide or import in each function.

+4
source

Source: https://habr.com/ru/post/1485657/


All Articles