当前位置:网站首页>What are the namespaces and function overloads of + and @ in front of MATLAB folder
What are the namespaces and function overloads of + and @ in front of MATLAB folder
2022-07-28 00:28:00 【slandarer】
Preface
When you open MATLAB Of toolbox Folder when ( Toolbox storage path ), You will find some strange symbols in front of the folder name :


??? Inside + and @ What are the ???
To explore this question , We have created a folder with the following directories :

Current folder ──@cell──dispTest.m
|
├──@double──dispTest.m
|
├──+test1──+test2──test.m
| |
| └──test.m
|
└──untitled.m
Namespace : Path function ( Directory structure )
If you want the code to be tidy , In many cases, some tool functions of the same kind will be placed in a separate folder , That is, the function you want to call is in a folder in the current folder , You cannot call this function directly in the current folder , What should I do ?
Many people will choose direct addpath, But in this case, those tool functions can be called by more than the project , Other items in other locations can also call , This may lead to naming conflicts .
Then a very simple method is to name the folder where the tool functions are installed +fordername In the form of , There is a + In the form of , In fact, the folder path is used as the namespace .
For the following parts of the catalog we proposed earlier :
Current folder ──+test1──+test2──test.m
| |
| └──test.m
|
└──untitled.m
I want to untitled.m Call in +test1 In folder test.m, You can call directly through the following code :
test1.test()
Of course, as shown in the catalogue ,+test1 There is also a plus sign in the folder +test2 Folder , We want to call... In that folder test.m, You can do it in the following ways :
test1.test2.test()
This call format is very similar to the function in the call structure , This is why I call it a directory structure .
Function overloading
Of course, next we will talk about what this part of the catalog is :
Current folder ──@cell──dispTest.m
|
├──@double──dispTest.m
|
└──untitled.m
It's like C++ Overloading of functions in , Two @classname Two functions with exactly the same name on the right in the folder of .
Notice what's going on here @ add Class name The format of , It can be MATLAB Own class , It can also be a self-defined class function , Here we set up the folder named by cell class and double precision class .
What's the use of this setting ? After this setting , For example, I will call dispTest.m Function , If the input variable is a cellular array , Then it will call @cell This function in the folder , If the input variable is double , Then it will call @double Functions in folders .
That is to say, there are two ways to write , Different functions are used :
dispTest(1)
dispTest({1})
Conclusion
That's about it , about + You can want to be a structure , about @ You can want to overload , The function definitions in my different folders are like this :
+test1\test.m
function test
disp(' Welcome to your attention slandarer forder1')
end
+test1+test2\test.m
function test
disp(' Welcome to your attention slandarer forder2')
end
@cell\dispTest.m
function dispTest(coe)
disp('is cell')
end
@double\dispTest.m
function dispTest(coe)
disp('is double')
end
So in untitled.m Run the following code , The effect is as follows :
test1.test()
test1.test2.test()
dispTest(1)
dispTest({
1})
Welcome to your attention slandarer forder1
Welcome to your attention slandarer forder2
is double
is cell
边栏推荐
- Tiktok live broadcast monitoring - round robin 24 hours - live broadcast barrage
- 看知名企业们如何利用 Web3进行产业重塑
- 【Meetup预告】OpenMLDB+OneFlow:链接特征工程到模型训练,加速机器学习模型开发
- Promoting cloud network integration and building a digital economy: Intel unveiled the 5th Digital China Construction Summit - cloud ecosystem Conference
- 永州出入境检验实验室建设那些事
- OpenVINO整合TensorFlow实现推理加速
- 2022最新抖音直播监控全套监控(五)商品详情监控
- The latest notice of the Chinese Academy of Sciences: abandon the impact factor! The journal zoning table will be published for the "Journal surpassing index"
- MATLAB | 那些你不得不知道的MATLAB小技巧(三)
- If we were the developer responsible for repairing the collapse of station B that night
猜你喜欢

Tiktok live broadcast monitoring - round robin 24 hours - live broadcast barrage

荣耀多款产品齐发,笔记本MagicBook V 14售价6199元起

『百日百题 · 基础篇』备战面试,坚持刷题 第三话——分支语句!

A few lines of code can easily realize the real-time reasoning of paddleocr. Come and get!

adb路径不能包含2空格remote couldn‘t create file: Is a directory

Oracle password expiration solution

Liux common commands (view and open firewall port number + view and kill process)

MFC提示this application has requested the runtime to terminate it in an unusual way editbox框已经删了还在使用

C语言实现五子棋游戏

See how well-known enterprises use Web3 to reshape their industries
随机推荐
Yongzhou water quality testing laboratory construction: Furniture description
窗口函数over
View the construction details of Yongzhou dioxin Laboratory
BuildForge 资料
The second uncle cured my spiritual internal friction and made me angry out of station B
2022最新抖音直播监控全套监控(五)商品详情监控
北欧岗位制博士申请有多难?
物联网有助于应对气候变化的 3 种方式
A great thinking problem cf1671d insert a progression
҈ straight ҈ Broadcast ҈ Pre ҈ Report ҈ |҈ In hot summer, let's cross the high temperature and "bake" with nono!
永州出入境检验实验室建设那些事
公司7月来了个软件测试工程师,一副毛头小子的样儿,哪想到是新一代卷王...
[C language] string reverse order (recursive implementation)
Tiktok live broadcast monitoring - round robin 24 hours - live broadcast barrage
Esp8266----- mqtt cloud device on cloud
Common errors reported by ant sword
『百日百题 · 基础篇』备战面试,坚持刷题 第三话——分支语句!
Build Release Blogs
Intel joins hands with hanshuo and Microsoft to release the "Ai + retail" trick!
[sel object of Objective-C language]