Assign values to a string in Matlab

2 次查看(过去 30 天)
For example I have:
X ='abcaaabc';
How can I get it like
Y= [a b c a a a b c];
and
Y1= [0 1 2 0 0 0 1 2]

回答(2 个)

Fangjun Jiang
Fangjun Jiang 2019-10-16
  1 个评论
Fangjun Jiang
Fangjun Jiang 2019-10-16
编辑:Fangjun Jiang 2019-10-16
You can't have the Y you want. Maybe Y=[X(:)], or Y=transpose(string(X'))

请先登录,再进行评论。


Stephen23
Stephen23 2019-10-16
>> X = 'abcaaabc';
>> Y = num2cell(X)
Y =
'a' 'b' 'c' 'a' 'a' 'a' 'b' 'c'
>> Y1 = X-97
Y1 =
0 1 2 0 0 0 1 2

类别

Help CenterFile Exchange 中查找有关 Data Types 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by