Organising a table of data
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
madhan ravi
2019-3-31
Smokers=T(T{:,'Smokers'}==1,1)
Non_Smokers=T(T{:,'Smokers'}==0,1) % where T is your table
1 个评论
madhan ravi
2019-3-31
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,:)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Descriptive Statistics and Visualization 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!