How can I convert a string containing numbers into a numeric array of these numbers?
1 view (last 30 days)
Show older comments
MathWorks Support Team
on 27 Jun 2009
Edited: MathWorks Support Team
on 14 Oct 2022
For example, I have:
a = '1 2 3 4 5'
I would like to get [1 2 3 4 5].
Accepted Answer
MathWorks Support Team
on 14 Oct 2022
Edited: MathWorks Support Team
on 14 Oct 2022
You can use STRREAD or SSCANF to convert a string containing numbers into a numeric array . For example:
a = '1 2 3 4 5'
b = strread(a,'%d')'
or
a = '1 2 3 4 5'
c = sscanf(a,'%d')'
You can get help on this or any other MATLAB function by typing 'doc' or 'help' without the quotes followed by the function name at the MATLAB command prompt. For instance, for help on STRREAD type:
doc strread
at the MATLAB command prompt.
To search for any MATLAB function documentation on the web, go to the following location:
and type the function name in the search box.
0 Comments
More Answers (0)
See Also
Categories
Find more on Characters and Strings in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!