2

I want to convert the string into numbers for example x=[abacaaaabb] I want to assign values a=1 b=2 and c=-1 and store in new matrix x=[1 2 1 -1....}

4

2 回答 2

7

您可以创建映射:

map = zeros(1,256);
map('abc') = [1, 2, -1];

然后你可以用你的输入索引它:

x = 'abacaaaabb';
mx = map(x);
于 2013-06-07T02:16:36.477 回答
0

一种更简单的方法(除非您的映射确实必须像您的示例中那样任意):

x=['abacaaaabb'];

数量 = x - 96

结果是

num =

     1     2     1     3     1     1     1     1     2     2
于 2013-06-07T06:09:12.857 回答