how do i split every digit of a string

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일

1 개 추천

S = '1234'; % Say this is your string....
num = S - '0';
num(1)
num(2)
num(3)

추가 답변 (1개)

Walter Roberson
Walter Roberson 2012년 11월 24일

1 개 추천

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'

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

태그

질문:

2012년 11월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by