Converting character matrix to number

I have a character matrix A that I want to convert to numbers B, but it doesn't work with str2num. Any tips? I tried B = str2num(A) but gives B = [].
A = ['02';'06';'07'];
B = [2;6;7];

댓글 수: 2

Your example shows a character matrix, not a "vertical string vector" nor a "character vector".
This is a vertical string vector:
S = ["02";"006";"4"]
S = 3×1 string array
"02" "006" "4"
This is a character vector:
V = '0001'
V = '0001'
whos
Name Size Bytes Class Attributes S 3x1 258 string V 1x4 8 char
John Taylor
John Taylor 2021년 3월 3일
Ok, thanks. Character matrix then.

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

답변 (1개)

Walter Roberson
Walter Roberson 2021년 3월 3일

0 개 추천

str2double(cellstr(A))
or
double(string(A))

카테고리

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

제품

릴리스

R2020a

질문:

2021년 3월 3일

댓글:

2021년 3월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by