@folder和+ folder [英] @folder and +folder
问题描述
MATLAB中以下文件夹名称的含义是什么?
What is the meaning of the following folder names in MATLAB?
-
@folder
-
+folder
@folder
+folder
我创建了一个使用classdef
语法的类Tata.m
.
我应该将其放入@folder
还是+folder
?
I've created a class Tata.m
which uses the classdef
syntax.
Should I put it in an @folder
or a +folder
?
我看过文档,但还不清楚
在哪种情况下应使用@folder
,在哪种情况下应使用+folder
.
I've looked at the documentation but it is not really clear
in which cases the @folder
should be used and in which cases the +folder
should be used.
推荐答案
+folder
部分是MATLAB软件包文件夹.如果将Tata.m
放在类似+folder/Tata.m
的位置,则MATLAB会将其称为类folder.Tata
.如果将其放置在someOtherFolder/Tata.m
或someOtherFolder/@Tata/Tata.m
之类的文件夹中,则MATLAB会将其称为Tata
.
The +folder
piece is a MATLAB package folder. If you place Tata.m
in a location like +folder/Tata.m
, it will be known to MATLAB as the class folder.Tata
. If you place it in a folder like someOtherFolder/Tata.m
, or someOtherFolder/@Tata/Tata.m
, it will be known to MATLAB as Tata
.
将classdef
文件放在类似@Tata
的类目录中以使您可以将某些(或全部)方法的定义放在单独的文件中很有用.
It can be useful to place a classdef
file in a class directory like @Tata
to allow you to put the definition of some (or all) methods in separate files.
doc 具有更多细节.
要尝试弄清@
目录:历史上,具有方法methodOne
和methodTwo
的类Tata
将需要以下文件:
To attempt to clarify the @
directories: historically, a class Tata
with methods methodOne
and methodTwo
would require the following files:
somePlaceOnThePath/@Tata/Tata.m
somePlaceOnThePath/@Tata/methodOne.m
somePlaceOnThePath/@Tata/methodTwo.m
在新"对象系统中,您仍然可以使用上面的布局,而无需进行修改.在另一个极端,您可以将Tata
的整个实现放在以下单个classdef
块中:
In the "new" object system, you can still use the layout above without modification. At the other extreme, you can place the entire implementation of Tata
in a single classdef
block in:
somePlaceOnThePath/Tata.m
如果您有一些大方法,或者想将类Tata
的实现分成几个文件以简化并行开发,则可以使用这样的classdef:
If you have some large methods, or want to split up the implementation of the class Tata
into several files to make parallel development simpler, you can take use a classdef like this:
%# somePlaceOnThePath/@Tata/Tata.m:
classdef Tata
methods
result = methodTwo(obj, arg)
function methodOne(obj)
disp('hello from methodOne');
end
end
end
还有
%# somePlaceOnThePath/@Tata/methodTwo.m:
function result = methodTwo(obj, arg)
% do stuff with obj and arg
end
严格来说,classdef
中的methodTwo
的高级声明是可选的,因为它使用的是默认访问说明符.如果您想将methodTwo
用作私有方法,则可以将其放置在methods (Access = private)
块中.
Strictly speaking, the advance declaration of methodTwo
in the classdef
is optional because it's using the default access specifiers. If you wanted to have methodTwo
be a private method, you could place it in a methods (Access = private)
block.
这篇关于@folder和+ folder的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!