Assign values to a string in Matlab

2 visualizzazioni (ultimi 30 giorni)
Laura Paola Goyeneche Gomez
Risposto: Stephen23 il 16 Ott 2019
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]

Risposte (2)

Fangjun Jiang
Fangjun Jiang il 16 Ott 2019
  1 Commento
Fangjun Jiang
Fangjun Jiang il 16 Ott 2019
Modificato: Fangjun Jiang il 16 Ott 2019
You can't have the Y you want. Maybe Y=[X(:)], or Y=transpose(string(X'))

Accedi per commentare.


Stephen23
Stephen23 il 16 Ott 2019
>> 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

Categorie

Scopri di più su Data Types in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by