Tables - Data extraction and processing with ifelse

조회 수: 1 (최근 30일)
Christopher McCausland
Christopher McCausland 2019년 11월 7일
답변: Christopher McCausland 2019년 11월 10일
Where I am at;
I have imported a csv file as a table.
Each row of the table holds 14 peices of information (stored as variables in the table) about a person. Age, sex (1 or 0), wether or not they have had previous attention (1 or 0) etc.
For arguments sake here's a table to try and explain what I am talking about; (thanks MATLAB)
Gender Age Location Height
__________ ___ _____________________________ ______
Smith {'Male' } 38 {'County General Hospital' } 71
Johnson {'Male' } 43 {'VA Hospital' } 69
Williams {'Female'} 38 {'St. Mary's Medical Center'} 64
Jones {'Female'} 40 {'VA Hospital' } 67
Brown {'Female'} 49 {'County General Hospital' } 64
From a second set of data I have generated a decision tree which is implemented in ifelse statments - proof of concept and easier explination than higher level methods.
For arguments sake the tree could look something like this;
% Note this code is not exhaustive just an example to make the point easier
if (age > 30) && (height <= 70) && (Gender == 1)
fprintf('The patient has identified as positive')
outcome = 'T'
elseif (age > 40) && (height <= 60) && (Gender == 1)
fprintf('The patient has identified as Negitive')
outcome = 'F'
elseif (age > 40) && (height <= 60) && (Gender == 0)
fprintf('The patient has identified as positive (5.08)')
outcome = 'F'
end
What I want to do:
I want to take the data from the import and run it through the decision tree of ifelse statements.
Finally my question.
Is there a way to extract each row from the table (all 14 variables) and run this through the ifelse statements to return the outcome of each row as true or false?
I know I can extract a row of information from a table with ;
R1 = csv(1,:)
I just cant figure out how to process that row with the if else statments, I am assuming each element still is associated with its variable?
Thanks,
Christopher

채택된 답변

Christopher McCausland
Christopher McCausland 2019년 11월 10일
For anyone that stubbles across this, MATLAB has an inbuilt function called rowfun which can apply functions to rows of a table.
Hope this helps,
Christopher

추가 답변 (0개)

카테고리

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

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by