Package folder management in matlab: '+' folder

Introduce

In MATLAB, in order to facilitate the management of classes and methods, you can use the package folder. That is, add a '+' sign in front of the folder name. Its role is to provide a namespace.

Examples

  • There is a package folder mypack. There is a method pkfcn.m in this directory; there is also a class folder @myclass
+mypack
+mypack/pkfcn.m  % a package function
+mypack/@myClass % class folder in a package
  • Call syntax
%定义package function
function z = pkfcn(x,y)
%定义package class
classdef myClass

%方法1:完整名称调用
%调用package function
z = mypack.pkfcn(x,y);
%创建类对象
obj=mypack.myclass(arg)
%调用类对象方法
obj.myMethod(arg)
%调用类的静态方法
mypack.myClass.stMethod(arg)

%方法2:import后,直接通过方法或类名称调用
import mypack.*
import mypack.myClass.*
%调用package function
z = pkfcn(x,y);
%创建类对象
obj=myclass(arg)
%调用类对象方法
obj.myMethod(arg)
%调用类的静态方法
myClass.stMethod(arg)

Note: When using this package management class and method. The parent folder of the package must be imported into the matlab path. For example, in this example, the parent folder of the + mypack folder is the temp folder, then add the temp folder to the search path

Published 47 original articles · Like 33 · Visit 310,000+

Guess you like

Origin blog.csdn.net/kaever/article/details/73849795