'How to convert a char array of lines of numbers including '↵' to integers in matlab?
I have variable 'txt' of the type char and I want to turn it into an array of integers:
txt = '-1 1 -3 -1↵ -7 -4 -2 -3 -1 -2↵ -2 -24 -3 -1 -2 -2 -1 -1↵ -3 -1 0 -1 -2 -3 -4 -5↵ -5 -2 -1 -1 -2 -11-15-27↵ -5 -7 -30-19-16-18-19-18↵ -5 -4 -28-28-19-13↵ -4 -3 -13 -6
'
size(txt)
ans =
1 160
num2str(txt)
ans =
'-1 1 -3 -1
-7 -4 -2 -3 -1 -2
-2 -24 -3 -1 -2 -2 -1 -1
-3 -1 0 -1 -2 -3 -4 -5
-5 -2 -1 -1 -2 -11-15-27
-5 -7 -30-19-16-18-19-18
-5 -4 -28-28-19-13
-4 -3 -13 -6
'
str2num(txt)
ans =
[]
double(txt) also return an array of numbers but they are not the same as the number in the txt array. How can I turn txt array into integers?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
