[20220901] [Matlab] Mutual conversion between Matlab strings and ASCII

1. String to ASCII code using abs()

abs('a');
abs(' ');

2. Use char() to convert ASCII code to string

char(97);
char(32);

3. How to create a fixed-length string of all spaces?

    Because you can use ones ( 1 , N ) ones(1, N)ones(1,N ) generates a fixed-length list, so you can use the conversion relationship between strings and ASCII codes to generate a list with all 32 elements, and then convert it to a string.

num_lis = 32 * ones(1, N);
str_all_space = char(num_lis);

Guess you like

Origin blog.csdn.net/weixin_40583722/article/details/126647680