当前位置:网站首页>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
边栏推荐
- 好漂亮的彩虹
- 细数国产接口协作平台的六把武器!
- 【21天学习挑战赛】K同学啊 邀你参加深度学习研讨班
- How to deal with the website after it is hacked and how to delete batch malicious code
- Strong collaboration and common development! Intel and Taiyi IOT held a seminar on AI computing box aggregation services
- JS event propagation capture stage bubbling stage onclick addeventlistener
- Legendary Internet Setup tutorial with graphic explanation - GOM engine
- 看知名企业们如何利用 Web3进行产业重塑
- 【读书会第13期】音视频文件的封装格式
- 元宇宙的应用场景展示
猜你喜欢

If we were the developer responsible for repairing the collapse of station B that night

Mqtt---mqtt.fx client software

Senior how to determine the standard of software test completion

Have you ever seen this kind of dynamic programming -- the stock problem of state machine dynamic programming (Part 2)

物联网有助于应对气候变化的 3 种方式
![[flight control development foundation tutorial 6] crazy shell · open source formation UAV SPI (six axis sensor data acquisition)](/img/75/509db67a580dd4b9849bea08845cc7.png)
[flight control development foundation tutorial 6] crazy shell · open source formation UAV SPI (six axis sensor data acquisition)

Shell programming specifications and variables

Intel joins hands with hanshuo and Microsoft to release the "Ai + retail" trick!

2022年中国网络视频市场年度综合分析

A few lines of code can easily realize the real-time reasoning of paddleocr. Come and get!
随机推荐
R语言使用hexSticker包将ggplot2包可视化的结果转换为六角图(六角贴、六角形贴纸、ggplot2 plot to hex sticker)
【读书会第13期】音视频文件的封装格式
Cache and MMU management
[BRE]软件构建发布自动化
Yongzhou water quality testing laboratory construction: Furniture description
几行代码轻松实现对于PaddleOCR的实时推理,快来get!
Intel joins hands with hanshuo and Microsoft to release the "Ai + retail" trick!
Database tuning - principle analysis and JMeter case sharing
永州水质检测实验室建设:家具说明
Matlab | those matlab tips you have to know (I)
How to realize fast recognition of oversized images
ADB path cannot contain 2 spaces remote could n't create file: is a directory
永州植物细胞实验室建设布局方案
Senior how to determine the standard of software test completion
View the construction details of Yongzhou dioxin Laboratory
NPM related information
The second uncle cured my spiritual internal friction and made me angry out of station B
If we were the developer responsible for repairing the collapse of station B that night
Promoting cloud network integration and building a digital economy: Intel unveiled the 5th Digital China Construction Summit - cloud ecosystem Conference
Annual comprehensive analysis of China's online video market in 2022