Converting character matrix to number

14 visualizzazioni (ultimi 30 giorni)
John Taylor
John Taylor il 3 Mar 2021
Commentato: John Taylor il 3 Mar 2021
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 Commenti
Stephen23
Stephen23 il 3 Mar 2021
Modificato: Stephen23 il 3 Mar 2021
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 il 3 Mar 2021
Ok, thanks. Character matrix then.

Accedi per commentare.

Risposte (1)

Walter Roberson
Walter Roberson il 3 Mar 2021
str2double(cellstr(A))
or
double(string(A))

Categorie

Scopri di più su Data Type Conversion in Help Center e File Exchange

Prodotti


Release

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by