If I have a 20-digit numeric string, how can I convert it to an array where the elements are the digits of the string?
조회 수: 1 (최근 30일)
이전 댓글 표시
For example, if I have a string, such as
n='9555688756196283262165034064'
how can I convert it to the vector
b=[9 5 5 5 6 8 8 7 5 6 1 9 6 2 8 3 2 6 2 1 6 5 0 3 4 0 6 4]?
I tried using the following code, but Matlab is not accurate, and the imprecisions throw off the rest of my script:
n='9555688756196283262165034064';
a=str2double(n);
b=num2str(a) - '0';
댓글 수: 0
답변 (2개)
Star Strider
2016년 11월 28일
This is not generally recommended, but it works here:
n = '9555688756196283262165034064';
b = n - '0'
b =
Columns 1 through 16
9 5 5 5 6 8 8 7 5 6 1 9 6 2 8 3
Columns 17 through 28
2 6 2 1 6 5 0 3 4 0 6 4
댓글 수: 0
Elias Gule
2016년 11월 29일
Ok, try this code:
n = '9555688756196283262165034064';
matrix = arrayfun(@str2double ,n);
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!