Convert single string with many numbers to vector

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!

 采纳的回答

hue_vec = str2double(regexp(hue,'\d+','match'))

1 个评论

If you have decimals then the expressions would be:
hue_vec = str2double(regexp(hue,'\d*[\.]?\d*','match'))

请先登录,再进行评论。

更多回答(3 个)

类别

帮助中心File Exchange 中查找有关 Sparse Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by