String matlab study notes 10_4MATLAB Representation

A string manipulation learn together matlab-

10_4 MATLAB string representation

Find useful, welcome to discuss mutual learning together - Follow Me

Reference books
"matlab programming and integrated application" Zhang Defeng waiting to thank Zhang's books, so I appreciate the matlab convenient
"MATLAB technical bible" Ge Ge Chaodeng edited thanks to the teacher's books, so I appreciate the efficient matlab

Symbol string in MATLAB

  • MATLAB as a row vector string, each element corresponding to a character; string is saved in a row vector, each element of the vector corresponds to a character.
  • MATLAB single quotes in the string in braces, 'attention is not double quotes
  • Each row number string string element matrix may vary, but the total number of each row must be the same in all strings.
  • Calculated for each row is calculated only single character string in quotation marks and spaces count portion different spaces between parentheses
  • In fact the root cause, MATLAB all the strings in the row are combined to form a string, with no spaces between a single string, which is the number of strings in each row can not enter the same
>> SA=['hello';'world';'我是许某某']
SB=['你好' '但是我不好' '有没有想过你为什么不好';'那不知道你为什么不好啊' '那就是 命运吧'] % 一行中的字符只算单引号中的,并且不计算单引号中的括号
SC=['hello' 'nihao';'world';'我是许某某'] % 两行的字符长度不同,所以会报错[1,10],[1,5],[1,5]

SA =

hello
world
我是许某某


SB =

你好但是我不好有没有想过你为什么不好
那不知道你为什么不好啊那就是 命运吧

串联的矩阵的维度不一致。

Here Insert Picture Description

  • Using this feature, you can use [] to connect an arbitrary string
>> [SA(1,:) SA(2,:) SA(3,:)]

ans =

helloworld我是许某某
  • For 'also possible identifications special characters, thus:
    Here Insert Picture Description

  • And numerical string identifying the same vector or matrix, i.e. can be extracted or re-assignment operations on elements
>> s1='My name is limomo'

s1 =

My name is limomo

>> s2=s1(1:end) % 是s1(1:1:end)的缩写,表示从头到尾进行取值,不间隔字符

s2 =

My name is limomo

>> s2=s1(1,:)

s2 =

My name is limomo

>> s2=s1(end:-1:1) % 是s1(end:-1:1,:)的缩写,表示从尾到头进行取值,不间隔字符

s2 =

omomil si eman yM
  • String String matrix and can add, subtract, multiply, four arithmetic and other mathematical operations. Since MATLAB mathematical operation between the string and the string is the data matrix as matrix processing, thereby carrying out these operations, in fact, by the ASCII code of each character string consisting of the data matrix. ASCII characters can be printed normally range between 32-127, while any 8-bit binary number in the range 0-255, if not a positive integer value, or beyond the above range, it is actually printed the ASCII code for the fix (rem (a, 256)) characters.
'a'+'b'
ans=195
'a'*'b'
ans=9506
abs('a')
ans=97
abs('b')
ans=98

Guess you like

Origin www.cnblogs.com/cloud-ken/p/11734052.html