else if statements on a table

조회 수: 7 (최근 30일)
ryan mccomb
ryan mccomb 2017년 11월 16일
댓글: AluminiumMan 2022년 9월 19일
I have a 60x12 table. Each row has patient data and the overall aim is using if and else if statements determine if the patients suffers from a particular disease. I am struggling to understand how to get the code of if and else if statements to analysis each row individually and produce an outcome for each row using my if and else if statements

답변 (1개)

KL
KL 2017년 11월 16일
You do not need if-else to filter data when you use a table. It would have been easier had you attached some sample data, aynway let's take the example from documentation.
First the table,
load patients
patients = table(Age,Gender,Height,Weight,Smoker,...
'RowNames',LastName);
T = patients(1:10,:);
Now, create a dummy data as a disease column,
Disease = logical(round(rand(10,1))); %dummy data
T.Disease = Disease; %add the column to the table
My table with this new column looks like,
T =
10×6 table
Age Gender Height Weight Smoker Disease
___ ________ ______ ______ ______ _______
Smith 38 'Male' 71 176 true false
Johnson 43 'Male' 69 163 false false
Williams 38 'Female' 64 131 false true
Jones 40 'Female' 67 133 false true
Brown 49 'Female' 64 119 false true
Davis 46 'Female' 68 142 false false
Miller 33 'Female' 64 142 true true
Wilson 40 'Male' 68 180 false false
Moore 28 'Male' 68 183 false false
Taylor 31 'Female' 66 132 false false
Now, if you want to see all the patients' details who have this disease,you say,
T(T.Disease==1,:)
result would be something like,
ans =
4×6 table
Age Gender Height Weight Smoker Disease
___ ________ ______ ______ ______ _______
Williams 38 'Female' 64 131 false true
Jones 40 'Female' 67 133 false true
Brown 49 'Female' 64 119 false true
Miller 33 'Female' 64 142 true true
if you want to check if a certain patient has this disease you say,
T('Smith','Disease')
then you get,
ans =
table
Disease
_______
Smith false
you can also combine multiple conditions like,
T(T.Smoker==1&T.Disease==1,:)
you get the result as,
ans =
1×6 table
Age Gender Height Weight Smoker Disease
___ ________ ______ ______ ______ _______
Miller 33 'Female' 64 142 true true
Hope you get an idea of how it works.
  댓글 수: 1
AluminiumMan
AluminiumMan 2022년 9월 19일
This is really useful. What about if the data is equal to or greater than a certain value? Rather than equalling a certain value?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Agriculture에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by