String array of the letters of the alphabet
35 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
the cyclist
el 10 de Feb. de 2023
Comentada: the cyclist
el 10 de Feb. de 2023
Is there a compact way to generate a string array with the letters of the English alphabet?
alphabet = ["a","b", .., "z"]
0 comentarios
Respuesta aceptada
Más respuestas (1)
John D'Errico
el 10 de Feb. de 2023
alf = 'a':'z'
It also works for caps.
ALF = 'A':'Z'
2 comentarios
John D'Errico
el 10 de Feb. de 2023
The obvious is:
alf = string('a':'z')
That makes a string array, but you wanted a set of scalar string arrays. So then I see that this will create the desired string array.
string({'a' 'b'})
And that means you can use mat2cell.
string(mat2cell('a':'z',1,ones(1,26)))
It feels a little kludgy. But it works. There may be a better way. If so, I'll probably think of it as soon as I click on submit.
Ver también
Categorías
Más información sobre Data Type Conversion en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!