Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
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....}
x=[abacaaaabb]
a=1 b=2 and c=-1
x=[1 2 1 -1....}
您可以创建映射:
map = zeros(1,256); map('abc') = [1, 2, -1];
然后你可以用你的输入索引它:
x = 'abacaaaabb'; mx = map(x);
一种更简单的方法(除非您的映射确实必须像您的示例中那样任意):
x=['abacaaaabb'];
数量 = x - 96
结果是
num = 1 2 1 3 1 1 1 1 2 2