当前位置:网站首页>MATLAB data type - character type
MATLAB data type - character type
2022-06-27 00:26:00 【Fanyi】
matlab Series articles : Catalog

〇、 summary
For Mathematics , Character data may not be very important , But it is necessary when it is used . Therefore, we have this introduction to character data .
ad locum , Character data is divided into character string and Character variables To introduce , The usage of the two is slightly different .
character : and Python、Java And other high-level language types , Focused on mathematical calculations matlab There are also character data in , like a、b Data with only one character .
character string : Simply speaking , A string is data composed of several characters , such as ab、adccsa etc. .
One 、 Creation of characters and strings
1. Character creation
(1) Character creation
① Create with single quotation marks
>> a = 'abcd'
a =
'abcd'
>>
>> whos
Name Size Bytes Class Attributes
a 1x4 8 char
② use char Function creation
>> b = char('abcasd')
b =
'abcasd'
>>
>> whos
Name Size Bytes Class Attributes
b 1x6 12 char
(2) Creation of character array
① The character array uses char Function creation
Character arrays also use char() Function creation .
>> a1 = char('abcasd','asdass')
a1 =
2×6 char Array
'abcasd'
'asdass'
>>
>> whos
Name Size Bytes Class Attributes
a1 2x6 24 char
2. String creation
(1) String creation
① Create... In double quotes
>> c = "hello" % " Create string
c =
"hello"
>>
>> whos
Name Size Bytes Class Attributes
c 1x1 150 string
② use string Function creation
>> d = "hello world" % string() Function to create a string
d =
"hello world"
>>
>> whos
Name Size Bytes Class Attributes
d 1x1 166 string
(2) Creation of character array
① The character array uses [] establish
>> c1 = ["hello" "world";"nihao" "hhh"] % Be careful , Vectors of different dimensions are represented by ; separate
c1 =
2×2 string Array
"hello" "world"
"nihao" "hhh"
>>
>> whos
Name Size Bytes Class Attributes
c1 2x2 312 string
Two 、 character And character string Related operations of
Although it is about character (char) And character string (string) Related operations of , But compared to character string (string) Come on , character (char) More use of , So here's the character (char) More .
1. Length of string
There are two commonly used functions to detect the length of a string —— length() And size(), But the situation is slightly different mainly for multiple latitudes .
length()Is to select the maximum value from multiple dimensions and returnsize()Is to return the length in multiple dimensions as a vector
① length function
>> a = 'abcdef'
a =
'abcdef'
>>
>> length(a)
ans =
6
② size function
>> a = 'abcdef'
a =
'abcdef'
>>
>> size(a)
ans =
1 6
2. String splicing
character (char) And character string (string) The splicing method is slightly different .
- character (
char) adoptstrcat()Function - character string (
string) Directly through+that will do
① String splicing
character (char) adopt strcat() Function .
>> x = 'abcde'
x =
'abcde'
>>
>> y = 'fghij'
y =
'fghij'
>>
>> z = strcat(x,y)
z =
'abcdefghij'
② String splicing
character string (string) Directly through + that will do .
>> a = "abc"
a =
"abc"
>>
>> b = "def"
b =
"def"
>>
>> c = a + b
c =
"abcdef"
3. String comparison
① String comparison
adopt strcmp() Function can compare two character or character string , When two characters are identical , The return value is 1; If different , The return value is 0.
- Format :
strcmp(s1,s2),s1 And s2 For two strings that need to be matched .
>> a = 'abcd'
a =
'abcd'
>>
>> b = 'abcd'
b =
'abcd'
>>
>> strcmp(a,b)
ans =
logical
1
4. Find string
① Find string
If we want to find a short string in a long string , You can use findstr() Function to find .
findstr()The function will find the substring in a string , If found, the starting position of each substring in the long string will be returned in the form of an array . If not found, an empty array will be returned .- Format :
findstr(s_long,s_short),s_longIs a long string ,s_shortIs a short string ( Substring )
>> a = 'I am a good boy'
a =
'I am a good boy'
>>
>> findstr(a,'o')
ans =
9 10 14
5. display string
disp()Is a function used to display strings , It's similar to Java、Python In languageprint()
>> a = 'I am a good boy'
a =
'I am a good boy'
>>
>> disp(a)
I am a good boy
6. Index of characters
Character indexing is also an important function : Characters can be indexed , The string cannot
① Index character
>> a = 'abcdef' %% character
a =
'abcdef'
>>
>> for i = 1:3 %% Index character
a(i)
end
ans =
'a'
ans =
'b'
ans =
'c'
② Index string
>> b = "abcdef" %% character string
b =
"abcdef"
>>
>> for i = 1:3 %% Index string
b(i)
end
ans =
"abcdef"
Index exceeds the number of array elements. Index must not exceed 1.
An exception occurs in the index string .

边栏推荐
- Memorizing byte order of big and small end
- Overview of Freescale MCU
- 利用burp精准定位攻击者
- 低佣金免费开户渠道安全吗?
- [microservices] understanding microservices
- Kubeadm create kubernetes cluster
- 【Mysql】时间字段默认设置为当前时间
- 新股民如何网上开户 网上开户炒股安全吗
- 全網最全的混合精度訓練原理
- Is it reliable to open an account for stock trading on the mobile phone? Is it safe to open an account for stock trading on the Internet
猜你喜欢

Common techniques of email attachment phishing

Technical dry goods | top speed, top intelligence and minimalist mindspore Lite: help Huawei watch become more intelligent

matlab数据类型 —— 字符型

當Transformer遇見偏微分方程求解

07 | 工作流设计:如何设计合理的多人开发模式?

kubeadm创建kubernetes集群

代码之外:写作是倒逼成长的最佳方式

redis详细教程

MindSpore新型轻量级神经网络GhostNet,在ImageNet分类、图像识别和目标检测等多个应用场景效果优异!

The most complete hybrid precision training principle in the whole network
随机推荐
Is it safe to open an account on the mobile phone to buy stocks? Is it safe to open an account on the Internet to speculate in stocks
JS library for number formatting
数字格式化的 js 库
冲刺强基计划数学物理专题二
Is it safe for CITIC Securities Commission to open an online account and speculate in stocks
Pinpoint attackers with burp
In the Internet industry, there are many certificates with high gold content. How many do you have?
Special topic II on mathematical physics of the sprint strong foundation program
My advanced learning notes of C language ----- keywords
com. fasterxml. jackson. databind. exc.MismatchedInputException: Expected array or string. at [Source:x
How to open an account on the mobile phone? Is it safe to open an account online and speculate in stocks
Is it reliable to open an account on a stock trading mobile phone? Is it safe to open an account online and speculate in stocks
我的c语言进阶学习笔记 ----- 关键字
From bitmap to bloom filter, C # implementation
Redis detailed tutorial
Technical dry goods | what is a big model? Oversized model? Foundation Model?
Cvpr2022 stereo matching of asymmetric resolution images
低佣金免费开户渠道安全吗?
Can't write to avoid killing and can easily go online CS through defender
Oracle 數據庫基本知識概念