Clear Filters
Clear Filters

convert string into number in table

9 views (last 30 days)
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

Accepted Answer

Star Strider
Star Strider on 7 Mar 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.

More Answers (0)

Categories

Find more on Input Specification in Help Center and File Exchange

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!