フィルターのクリア

The best way to input a table with a unique format

1 回表示 (過去 30 日間)
Andrew Czeizler
Andrew Czeizler 2019 年 3 月 6 日
コメント済み: Adam Danz 2019 年 3 月 14 日
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 件のコメント
Adam Danz
Adam Danz 2019 年 3 月 13 日
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 2019 年 3 月 13 日
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

サインインしてコメントする。

採用された回答

Adam Danz
Adam Danz 2019 年 3 月 13 日
編集済み: Adam Danz 2019 年 3 月 14 日
(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 件のコメント
Andrew Czeizler
Andrew Czeizler 2019 年 3 月 14 日
So detailed!
Thank you so much Adam, really clear :).
Best,
Andrew
Adam Danz
Adam Danz 2019 年 3 月 14 日
High five!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTables についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by