当前位置:网站首页>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
边栏推荐
猜你喜欢

See how well-known enterprises use Web3 to reshape their industries

千万播放竟有通用公式?B站被小看的爆款机会!

Oracle密码过期解决办法

ADB path cannot contain 2 spaces remote could n't create file: is a directory

How difficult is it to apply for a doctorate under the post system in northern Europe?

2022最新抖音直播监控全套监控(五)商品详情监控

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

MATLAB | 那些你不得不知道的MATLAB小技巧(一)

҈直҈播҈预҈告҈ |҈ 炎热盛夏,与Nono一起跨越高温“烤”验吧!

二舅治好我的精神内耗,也让我火出了B站
随机推荐
[geek challenge 2019] rce me
Strong collaboration and common development! Intel and Taiyi IOT held a seminar on AI computing box aggregation services
每次读取一行字符串输入(有待补充)
Legendary Internet Setup tutorial with graphic explanation - GOM engine
JS ATM机输出
"Digital economy, science and technology for the good" talk about dry goods
Mqtt---mqtt.fx client software
JS 事件传播 捕获阶段 冒泡阶段 onclick addEventListener
Intel releases open source AI Reference Suite
Common errors reported by ant sword
Intel joins hands with hanshuo and Microsoft to release the "Ai + retail" trick!
Diffusion + super-resolution model strong combination, the technology behind Google image generator image
30余年的元宇宙,为我们带来了什么?
「图神经网络:基础、前沿与应用」最新IJCAI2022教程
Openvino integrates tensorflow to accelerate reasoning
冲量在线出席2022数据要素安全流通论坛—政务领域专场,助力行业政务大数据建设创新发展
C# 事件相关的练习代码。
MATLAB | 那些你不得不知道的MATLAB小技巧(二)
Remote monitoring of pump station
新媒体内容输出方式-短视频