Convert single string with many numbers to vector
31 次查看(过去 30 天)
显示 更早的评论
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!
0 个评论
采纳的回答
madhan ravi
2019-7-31
hue_vec = str2double(regexp(hue,'\d+','match'))
1 个评论
madhan ravi
2019-7-31
If you have decimals then the expressions would be:
hue_vec = str2double(regexp(hue,'\d*[\.]?\d*','match'))
更多回答(3 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Numeric Types 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!