本文介绍了Matlab中的字符串和字符有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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.

推荐答案

文档建议:

这是两种表示形式的区别:

This is how the two representations differ:

  • 元素访问权限.为了表示不同长度的char向量,必须使用cell数组,例如ch = {'a', 'ab', 'abc'}.使用字符串,可以在实际数组中创建它们:str = [string('a'), string('ab'), string('abc')].但是,要在字符串中索引字符直接使用数组,必须使用大括号表示法:

  • 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'

  • 内存使用量.字符每个字符正好使用两个字节. string有开销:

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

    a = 'abc'
    b = string('abc')
    whos a b
    

    返回

    Name      Size            Bytes  Class     Attributes
    
     a         1x3                 6  char
     b         1x1               132  string
    

  • 这篇关于Matlab中的字符串和字符有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    05-26 23:46
    查看更多