Organising a table of data

1 Ansicht (letzte 30 Tage)
Ame Michael
Ame Michael am 31 Mär. 2019
Bearbeitet: per isakson am 18 Apr. 2019
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 Kommentar
Peter Perkins
Peter Perkins am 2 Apr. 2019
Based on that error, you DON'T have a table. Figure out what "data" is.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

madhan ravi
madhan ravi am 31 Mär. 2019
Smokers=T(T{:,'Smokers'}==1,1)
Non_Smokers=T(T{:,'Smokers'}==0,1) % where T is your table
  1 Kommentar
madhan ravi
madhan ravi am 31 Mär. 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,:)

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Descriptive Statistics and Visualization finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by