MatLab---字符串,字符数组与文本操作常用函数
2022/4/25 23:15:14
本文主要是介绍MatLab---字符串,字符数组与文本操作常用函数,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
1.class():测试变量类型
Apple_char='Apple'
Apple_char =
'Apple'
>> class(Apple_char)
ans =
'char'
>> Apple_string="Appple"
Apple_string =
"Appple"
>> class(Apple_string)
ans =
'string'
2.强制类型转换成double
double(Apple_char)
ans =
65 112 112 108 101
行数和列数
>> size(Apple_char)
ans =
1 5
行数和列数,较大的值
>> length(Apple_char)
ans =
5
字符的转置
>> Apple_char'
ans =
5×1 char 数组
'A'
'p'
'p'
'l'
字符以数组的形式存储
Apple_char(2)
ans =
'p'
>> Apple_char(4)
ans =
'l'
>> size(Apple_string)
ans =
1 1
>> Apple_string
Apple_string =
"Appple"
char是数组,向量而string是一个标量
>> Apple_char% 数组/向量
Apple_char =
'Apple'
>> Apple_string%标量
Apple_string =
"Appple"
>> length(Apple_string)
ans =
1
>> Apple_string(1)
ans =
"Appple"
vector=[1 2 3 4]
vector =
1 2 3 4
>> vector(1)
ans =
1
>> scale=pi %scale是个标量
scale =
3.1416
>> scale(2)
索引超出数组元素的数目(1)。
'scale' 似乎同时为函数和变量。如果这不是预期的情况,请使用 'clear scale' 将变量 'scale' 从工作区中删除。
>> scale(1)
ans =
3.1416
Apple_string{1} %类型发生了改变,变成char
ans =
'Appple'
>> Apple_string{1}(2)
ans =
'p'
>> Apple_string{1} %类型发生了改变,变成char
ans =
'Appple'
major_string=["English","History","Engineering"]
major_string =
1×3 string 数组
"English" "History" "Engineering"
major_char=['English','History','Engineering'] %[1:3 4:7 5:9]
major_char =
'EnglishHistoryEngineering'
>> major_char=char('English','History','Engineering') %char的强制类型转换
major_char =
3×11 char 数组
'English '
'History '
'Engineering'
>> %注意用空格补齐,如果字符本身结尾处就有空格,就会出现问题
空值问题:
[' ',' ']
ans =
空的 0×0 char 数组
>> % " "还是标量
>> [" "," "]
ans =
1×2 string 数组
"" ""
空格表示
blanks(4)
ans =
' '
repmat()的用法
>> repmat([1 2 3],4,3)
ans =
1 2 3 1 2 3 1 2 3
1 2 3 1 2 3 1 2 3
1 2 3 1 2 3 1 2 3
1 2 3 1 2 3 1 2 3
>> repmat('a',4,3)
ans =
4×3 char 数组
'aaa'
'aaa'
'aaa'
'aaa'
>> repmat('ab',4,3)
ans =
4×6 char 数组
'ababab'
'ababab'
'ababab'
'ababab'
方括号的组合功能:
>> ['Space' blanks(4) 'Cowboy']
ans =
'Space Cowboy' %将三个独立的字符串,合并到一起;
这篇关于MatLab---字符串,字符数组与文本操作常用函数的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-19永别了,微服务架构!
- 2024-05-15鸿蒙生态设备数量超8亿台
- 2024-05-13TiDB + ES:转转业财系统亿级数据存储优化实践
- 2024-05-09“2024鸿蒙零基础快速实战-仿抖音App开发(ArkTS版)”实战课程已上线
- 2024-05-09聊聊如何通过arthas-tunnel-server来远程管理所有需要arthas监控的应用
- 2024-05-09log4j2这么配就对了
- 2024-05-09nginx修改Content-Type
- 2024-05-09Redis多数据源,看这篇就够了
- 2024-05-09Google Chrome驱动程序 124.0.6367.62(正式版本)去哪下载?
- 2024-05-09有没有大佬知道这种数据应该怎么抓取呀?