Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
675 views
in Technique[技术] by (71.8m points)

matlab - @folder and +folder

What is the meaning of the following folder names in MATLAB?

  • @folder
  • +folder

I've created a class Tata.m which uses the classdef syntax. Should I put it in an @folder or a +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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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.

The doc has more details.

EDIT: 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

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

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

And also

%# somePlaceOnThePath/@Tata/methodTwo.m:
function result = methodTwo(obj, arg)
% do stuff with obj and arg
end

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.8k users

...