convert string into number in table

9 次查看(过去 30 天)
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

采纳的回答

Star Strider
Star Strider 2020-3-7
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Input Specification 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by