Effacer les filtres
Effacer les filtres

The best way to input a table with a unique format

1 vue (au cours des 30 derniers jours)
Andrew Czeizler
Andrew Czeizler le 6 Mar 2019
Commenté : Adam Danz le 14 Mar 2019
Hi all,
I have a table that has the following format-
tabletobuild.png
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 commentaires
Adam Danz
Adam Danz le 13 Mar 2019
The question isn't clear to me. Are you asking wether the format of this table will work with your project?
Andrew Czeizler
Andrew Czeizler le 13 Mar 2019
Hi Adam!
I'm asking the best method to input the table into matlab, so to be able to perform operations on the table.
many thanks
best,
Andrew

Connectez-vous pour commenter.

Réponse acceptée

Adam Danz
Adam Danz le 13 Mar 2019
Modifié(e) : Adam Danz le 14 Mar 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 commentaires
Andrew Czeizler
Andrew Czeizler le 14 Mar 2019
So detailed!
Thank you so much Adam, really clear :).
Best,
Andrew
Adam Danz
Adam Danz le 14 Mar 2019
High five!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Tables dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by