Filter löschen
Filter löschen

convert string into number in table

9 Ansichten (letzte 30 Tage)
Tomasz Kaczmarski
Tomasz Kaczmarski am 7 Mär. 2020
Beantwortet: Star Strider am 7 Mär. 2020
Hi
attached file is a table with
'STANDING','SITTING','LAYING','WALKING','WALKING_DOWNSTAIRS','WALKING_UPSTAIRS'
could you please help how to convert them into numers
i tired
targetSet1 = table2array(TargetSet)
z = cellfun(@(x){x(1),x(2),x(3:end)},targetSet1,'un',0);
TargetSet = str2double([z{:}]);
but its converting all into Nan plus output is in columns not rows
i need output as single column in double format where the values are numeric only
Thank you in advance

Akzeptierte Antwort

Star Strider
Star Strider am 7 Mär. 2020
I am not certain what you intend by ‘numbers’, so guessing:
D = load('TargetSet.mat');
TargetSet = D.TargetSet;
ActivityCode = table(findgroups(TargetSet.Activity), 'VariableNames',{'ActivityCode'});
TargetSet = [TargetSet, ActivityCode];
First15Rows = TargetSet(1:15,:)
producing:
First15Rows =
Activity ActivityCode
___________ ____________
{'LAYING' } 1
{'LAYING' } 1
{'LAYING' } 1
{'LAYING' } 1
{'LAYING' } 1
{'LAYING' } 1
{'LAYING' } 1
{'LAYING' } 1
{'LAYING' } 1
{'LAYING' } 1
{'SITTING'} 2
{'LAYING' } 1
{'LAYING' } 1
{'LAYING' } 1
{'LAYING' } 1
If you want a different result, please describe it in some detail.

Weitere Antworten (0)

Kategorien

Mehr zu Input Specification finden Sie in Help Center und File Exchange

Produkte


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by