how do i split every digit of a string

2 次查看(过去 30 天)
i have a string as '1111' how to split its digit as
num(1)=1
num(2)=1
num(3)=1
num(4)=1
I will always have numbers only in the string
thanks in advance

采纳的回答

Matt Fig
Matt Fig 2012-11-24
编辑:Matt Fig 2012-11-24
S = '1234'; % Say this is your string....
num = S - '0';
num(1)
num(2)
num(3)

更多回答(1 个)

Walter Roberson
Walter Roberson 2012-11-24
num = '1111'
then
num(1) would be '1'
If you need num(1) to be numeric 1 rather than the character 1, then
num = '1111' - '0'

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by