Convert string to array of numbers in matlab

I have a script in which a string of number is entered

string='123' 

or

 string='9823' 

I am trying to convert this to an array of the form [a, b, c, d] for example, from the string '123' to a number array [1,2,3]

Any tips on how to do this?

+5
source share
3 answers
 str = '123'; num = str - '0'; % num = [1 2 3]; 
+24
source

use str2num() function

 str = '123'; str = str2num(str); 

Note. To make sure I'm right, type "whos str" in the command window and check the class. A string has a class, char, and numeric values ​​have a class, double

0
source

You can use cellstr:

 cellstr('123') ans = { [1,1] = 123 } 
0
source

All Articles