The best way to input a table with a unique format
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Andrew Czeizler
el 6 de Mzo. de 2019
Comentada: Adam Danz
el 14 de Mzo. de 2019
Hi all,
I have a table that has the following format-
I am trying to find the best method to build the table in matlab.
I have tried the following -
systolic=[-inf 119;-inf 119; 120 129;120 129]
diastolic=[-inf 79;-inf 79; 80 84;80 84]
gender={'Female'; 'Male'; 'Female'; 'Male' }
value= [-3; 0; 0;0]
bpt= table(systolic, diastolic, gender, value)
but I only get the diagonal values.
Any help would be very much appreciated.
Best,
Andrew
5 comentarios
Adam Danz
el 13 de Mzo. de 2019
The question isn't clear to me. Are you asking wether the format of this table will work with your project?
Respuesta aceptada
Adam Danz
el 13 de Mzo. de 2019
Editada: Adam Danz
el 14 de Mzo. de 2019
(Continuing from comment section under the question)
The best format for a table depends on how you plan on interacting with the table. Basic tidy data principles suggest forming tables that have one row per observation and one column per variable. That makes it really easy to access and interact with single variables. Your current table is organized such the systolic and diastolic columns contain [1 x 2] vectors of [low, high] ranges. You could split that into their own columns like this.
systolic=[-inf 119;-inf 119; 120 129;120 129]
diastolic=[-inf 79;-inf 79; 80 84;80 84]
systolicLow = systolic(:,1);
systolicHigh = systolic(:,2);
diastolicLow = diastolic(:,1);
diastolicHigh = diastolic(:,2);
gender={'Female'; 'Male'; 'Female'; 'Male' }
value= [-3; 0; 0;0]
bpt= table(systolicLow, systolicHigh, diastolicLow, diastolicHigh, gender, value)
bpt =
4×6 table
systolicLow systolicHigh diastolicLow diastolicHigh gender value
___________ ____________ ____________ _____________ ________ _____
-Inf 119 -Inf 79 'Female' -3
-Inf 119 -Inf 79 'Male' 0
120 129 80 84 'Female' 0
120 129 80 84 'Male' 0
Now it will be easier to interact with the data. For example, which row classifies the following data?
syst = 122;
dias = 81;
gender = 'Female';
rowIdx = bpt.systolicLow < syst & bpt.systolicHigh >= syst & ...
bpt.diastolicLow < dias & bpt.diastolicHigh >= dias & ...
strcmpi(bpt.gender, gender);
bpt(rowIdx,:)
ans =
1×6 table
systolicLow systolicHigh diastolicLow diastolicHigh gender value
___________ ____________ ____________ _____________ ________ _____
120 129 80 84 'Female' 0
bpt.value(rowIdx,:)
ans =
0
2 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Tables en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!