MATLAB Answers

how do i split every digit of a string

15 views (last 30 days)
Sharen H
Sharen H on 24 Nov 2012
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

  0 Comments

Sign in to comment.

Accepted Answer

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

  1 Comment

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 24 Nov 2012
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'

  1 Comment

Sign in to comment.

Sign in to answer this question.

Tags