matlab 定义string_Matlab中的字符串和字符有什么区别?

What is the difference between string and character class in MATLAB?

a = 'AX'; % This is a character.

b = string(a) % This is a string.

解决方案There are two ways to represent text in MATLAB®. You can store text in character arrays. A typical use is to store short pieces of text as character vectors. And starting in Release 2016b, you can also store multiple pieces of text in string arrays. String arrays provide a set of functions for working with text as data.

This is how the two representations differ:

Element access. To represent char vectors of different length, one had to use cell arrays, e.g. ch = {'a', 'ab', 'abc'}. With strings, they can be created in actual arrays: str = [string('a'), string('ab'), string('abc')].

However, to index characters in a string array directly, the curly bracket notation has to be used:

str{3}(2) % == 'b'

Memory use. Chars use exactly two bytes per character. strings have overhead:

a = 'abc'

b = string('abc')

whos a b

returns

Name Size Bytes Class Attributes

a 1x3 6 char

b 1x1 132 string

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值