필터 지우기
필터 지우기

Accessing a specific char in a string

조회 수: 2 (최근 30일)
Harel Harel Shattenstein
Harel Harel Shattenstein 2016년 11월 28일
댓글: Harel Harel Shattenstein 2016년 11월 28일
I am trying to access a specific char in a string.
I get a number by the user and I need to index all the digits, because the number is saved in a vector the only way to access it will be by using the mod operation.
So I thought of a shorter way, because the number is an integer, I can turn it into a string and then use an index to access the desirable.
For example:
A=num2str(18345); A(2) 8
Can I access the char without saving in to a variable first? num2str(18345)(2) does not work
Thanks

답변 (1개)

KSSV
KSSV 2016년 11월 28일
a = 18345 ;
iwant = num2str(a) - '0' ;
iwant is a double, you can access any index.
  댓글 수: 1
Harel Harel Shattenstein
Harel Harel Shattenstein 2016년 11월 28일
Thanks, Can you please explain what happens?

댓글을 달려면 로그인하십시오.

카테고리

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