Organising a table of data
2 views (last 30 days)
Show older comments
Hi, I have some tables of data, and for convenience I will just show a small segment of it:
BloodPressure=
123
134
136
234
144
Smokers=
1
0
0
1
1
The rows of both BloodPressure and Smokers correspond, ie. the subject with BloodPressure 123 has a Smokers value of 1 (indicating that they are a smoker).
I would like to organise this table so that I can create a group containing all of the smokers and non-smokers, with their corresponding blood pressure.
I tried doing it using: group1 = data(data.Smokers == 1, 1) to create a group of smokers, where I created data to be
123 1
134 0
136 0
234 1
144 1
(ie. Just grouping the blood pressure and the smokers value together correspondingly.)
however, I get the error: Struct contents reference from a non-struct array object.
I appreciate any help,
thankyou.
1 Comment
Answers (1)
madhan ravi
on 31 Mar 2019
Smokers=T(T{:,'Smokers'}==1,1)
Non_Smokers=T(T{:,'Smokers'}==0,1) % where T is your table
1 Comment
madhan ravi
on 31 Mar 2019
T=table;
T.BloodPressure=[...
123
134
136
234
144]
T.Smokers= [...
1
0
0
1
1]
Smokers=T(T{:,'Smokers'}==1,:)
Non_Smokers=T(T{:,'Smokers'}==0,:)
See Also
Categories
Find more on Tables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!