matlab string 英语,MATLAB String Arrays

Code Compatibility

MathWorks is taking the following steps to address code compatibility from release to release:

The use of char and cell will be supported indefinitely.

The use of character vectors (char) and cell arrays of character vectors (cell) will continue to be supported in both MATLAB and Simulink. Functions and properties continue to accept and return them where they have in the past.

Functions and properties will continue to return the same text type.

Functions and properties introduced prior to R2018b will continue to return the text type they always have (either character vectors or cell arrays of character vectors). However, functions such as replaceBetween or join are an exception to this. These functions output the same text format as the input, enabling you to use these new text manipulation functions regardless of the text type you are using (string arrays, character vectors, or cell arrays of character vectors).

String arrays can be indexed using curly braces.

String arrays index in the same way as other MATLAB arrays. When you index a string array with parentheses () you get back a new string array. When you index a cell array with parentheses () you get back a new cell array. However, to access character vectors in a cell array, most code uses curly brace indexing. Curly brace indexing has been added to string arrays, and it is designed to return character vectors in order to be compatible with this cell array behavior.

If you maintain code for others, you should update your code to accept strings as well. Learn how from the following blog post: Accept string inputs in your code.

When Not to Use String Arrays

You can use string arrays for text data nearly everywhere in MATLAB code, but they are not intended to be used for:

Cell Arrays of Only Scalar Strings

In R2018b, we recommend that you use string arrays instead of cell arrays of character vectors to represent text. If you choose to use a cell array containing only text with functions such as lower, use them with the character vectors these functions expect. Avoid using these functions with cell arrays of strings.

Use:             >> lower(["Run1" "Run2" "Run3"])

Or use:        >> lower({'Run1' 'Run2' 'Run3'})

Do not use: >> lower({"Run1" "Run2" "Run3"})

Command Form

When used in command form, functions such as save, cd, and addpath continue to parse double quotes as text rather than as a delimiter. This behavior has been maintained to prevent code incompatibilities with commands such as mex.

Use:                  >> load 'my data.csv'

Do not use:      >> load "my data.csv"

See the string arrays documentation to learn more about the key differences between string arrays and character arrays and how to troubleshoot unexpected results.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值