Convert single string with many numbers to vector
29 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
madhan ravi
on 31 Jul 2019
hue_vec = str2double(regexp(hue,'\d+','match'))
1 Comment
madhan ravi
on 31 Jul 2019
If you have decimals then the expressions would be:
hue_vec = str2double(regexp(hue,'\d*[\.]?\d*','match'))
More Answers (3)
See Also
Categories
Find more on Numeric Types in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!