Hello, i have a question
(1) a string, '1101111000111101' (length 16)
how to into array [1 1 0 1 1 1 1 0 0 0 1 1 1 1 0 1]
if i use str2num, the result is 1.101111000111101e+15
Please if anyone knows the answer help me
(2) a array [1 1 0 1 1 1 1 0 0 0 1 1 1 1 0 1]
how to trans to string '1101111000111101'
Please if anyone knows the answer help me
thanks very much!!

답변 (3개)

Fangjun Jiang
Fangjun Jiang 2016년 9월 8일

1 개 추천

'1101111000111101'-48
sprintf('%d',[1 1 0 1 1 1 1 0 0 0 1 1 1 1 0 1])

댓글 수: 2

Andrei Bobrov
Andrei Bobrov 2016년 9월 9일
+1
Another option to get back a string is to simply revert the previous operation:
v = [1 1 0 1 1 1 1 0 0 0 1 1 1 1 0 1];
char(v + '0')

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

dpb
dpb 2016년 9월 8일
편집: dpb 2016년 9월 8일

1 개 추천

More generic for the numeric conversion is
sscanf('1101111000111101','%1d')
as can set the field width; the subtraction "trick" works for single digits, correct; however, I'd write
'1101111000111101'-48
as
'1101111000111101'-'0'
instead to remove the "magic number" 48 from the expression just as a stylistic change.
Yu-Kuan Chang
Yu-Kuan Chang 2016년 9월 9일

0 개 추천

thanks! the question 1 has been solve.
the question 2
a array [1 1 0 1 1 1 1 0 0 0 1 1 1 1 0 1]
how to trans to string '1101111000111101'
Please if anyone knows the answer help me

댓글 수: 1

dpb
dpb 2016년 9월 9일
편집: Fangjun Jiang 2016년 9월 12일
Fangjun already did; didn't you try it to see, even?

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

카테고리

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

질문:

2016년 9월 8일

댓글:

2016년 9월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by