当前位置:网站首页>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
边栏推荐
- AI briefing how to use loss surfaces a model integration
- Server open sensitive port
- 千万播放竟有通用公式?B站被小看的爆款机会!
- Overview of construction site selection of Yongzhou analytical laboratory
- What a beautiful rainbow
- HarmonyOS 3纯净模式可限制华为应用市场检出的风险应用获取个人数据
- C# 事件相关的练习代码。
- Read one line of string input each time (to be supplemented)
- 蚁剑常见报错
- Openvino integrates tensorflow to accelerate reasoning
猜你喜欢

Window function over

Promoting cloud network integration and building a digital economy: Intel unveiled the 5th Digital China Construction Summit - cloud ecosystem Conference

看知名企业们如何利用 Web3进行产业重塑

Remote monitoring of pump station

Application scenario Display of metauniverse

服务器中毒了——菜是原罪

2022 latest Tiktok live broadcast monitoring full set of monitoring (V) product details monitoring

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

【C语言】字符串逆序(递归实现)

In the third week of July, the list of feigua data station B up main ranking list was released!
随机推荐
Is it amazing to extract text from pictures? Try three steps to realize OCR!
adb路径不能包含2空格remote couldn‘t create file: Is a directory
泵站远程监控
Build Release Blogs
Intel joins hands with hanshuo and Microsoft to release the "Ai + retail" trick!
新媒体内容输出方式-短视频
30余年的元宇宙,为我们带来了什么?
ESP8266-----MQTT云下设备上云
MATLAB | 那些你不得不知道的MATLAB小技巧(四)
[flight control development foundation tutorial 6] crazy shell · open source formation UAV SPI (six axis sensor data acquisition)
C event related exercise code.
See how well-known enterprises use Web3 to reshape their industries
MFC prompts that this application has requested the runtime to terminate it in an unused way editbox box has been deleted and is still in use
[sel object of Objective-C language]
Those "experiences and traps" in the data center
Matlab | those matlab tips you have to know (I)
Promoting cloud network integration and building a digital economy: Intel unveiled the 5th Digital China Construction Summit - cloud ecosystem Conference
永州水质检测实验室建设:家具说明
Prepare for the interview and stick to the third sentence of the question - Branch sentences!
Three ways for the Internet of things to help cope with climate change