Matlab中@文件夹/+文件夹,类的点滴知识点

      matlab中带“+”和“@”字符命名的文件夹是matlab中的一种文件包, 比如:+folder/Tata.m ,matlab就知道这是一个Tata类文件夹;如果你按照普通的命名方式,比如:someOtherFolder/Tata.m ,或者someOtherFolder/@Tata/Tata.m ,这样matlab只能知道这是一个Tata.m文件。

      如果你要用classdef定义一些类,用@Tata的形式,可以把一些方法分别放在不同的路径目录下。以下的例子进一步阐明@目录的用法: Tata 类,方法methodOne 和 methodTwo

somePlaceOnThePath/@Tata/Tata.m
somePlaceOnThePath/@Tata/methodOne.m
somePlaceOnThePath/@Tata/methodTwo.m


你也可以把所有用到的方法放在一个单独的文件中:

somePlaceOnThePath/Tata.m

如果你所写的方法比较复杂,而你又想把它放在不同的文件中以方便查阅和管理,可以如下般使用classdef

文件一:

%# somePlaceOnThePath/@Tata/Tata.m:
classdef Tata
    methods
         result =methodTwo(obj,arg)
         functionmethodOne(obj)
             disp('hello from methodOne');
         end
    end
end

文件二:

%# somePlaceOnThePath/@Tata/methodTwo.m:
functionresult =methodTwo(obj,arg)
%dostuff withobj andarg
end

严格来讲,methodTwoclassdef中的声明是可以省略的,因为这里使用了默认的说明符。如果想把methodTwo作为私有方法,可以用 (Access = private) 

猜你喜欢

转载自blog.csdn.net/SMF0504/article/details/78839918