Convert string array to numetric.

2 Ansichten (letzte 30 Tage)
dmfwlansejr
dmfwlansejr am 18 Jan. 2023
Beantwortet: Stephen23 am 18 Jan. 2023
Hi- Everybody
I want to convert as below.
>> whos data
Name Size Bytes Class Attributes
Tdat 6848125x1 369798846 string
>> data(6:10,1)
ans =
5×1 string array
"01"
"01"
"10"
"10"
"01"
Convert to below..
I want to make...
>> data(:,1)
0
0
1
1
0
:
:
>> data(:,2)
1
1
0
0
1
:
:
Thanks!

Antworten (3)

Paul
Paul am 18 Jan. 2023
If the data only contains 0's and 1's ..
data = [
"01"
"01"
"10"
"10"
"01"]
data = 5×1 string array
"01" "01" "10" "10" "01"
data = double([extractBefore(data,2) extractAfter(data,1)])
data = 5×2
0 1 0 1 1 0 1 0 0 1

Stephen23
Stephen23 am 18 Jan. 2023
data = ["01";"01";"10";"10";"01"]
data = 5×1 string array
"01" "01" "10" "10" "01"
M = char(data)-'0'
M = 5×2
0 1 0 1 1 0 1 0 0 1

Star Strider
Star Strider am 18 Jan. 2023
Try something like this —
sv = ["01"
"01"
"10"
"10"
"01"];
cv = char(sv);
for k = 1:size(cv,1)
data(k,1) = str2double(cv(k,1));
data(k,2) = str2double(cv(k,2));
end
data
data = 5×2
0 1 0 1 1 0 1 0 0 1
.

Kategorien

Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by