Convert single string with many numbers to vector
Mostrar comentarios más antiguos
I have the following string
hue = '10 20 30 40 50';
That I want to turn into a vector of those 5 values
hue_vec = [10 20 30 40 50];
How can I do this? Thanks in advance!
Respuesta aceptada
Más respuestas (3)
Fangjun Jiang
el 31 de Jul. de 2019
1 voto
a=str2num(hue);
Very simple, very efficient, no evil eval:
>> hue = '10 20 30 40 50';
>> vec = sscanf(hue,'%f',[1,Inf])
vec =
10 20 30 40 50
Pati Stan
el 31 de Jul. de 2019
0 votos
Categorías
Más información sobre Sparse Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!