looping through rows one at a time putting each row through a set of if statements to create a table of outcomes

1 次查看(过去 30 天)
Hey Guys. I am looking help with some code I wish to write. I have used code to write a decision tree from weka and take data from an Excel file manually by typing in each variable when prompted.
I have done this code fine but I want to make this efficient and instead take the data from the Excel file, then row by row put it through my set of if and elseif statements of the tree. The aim is to determine the outcome of the patient based on numerous variables.
column 1 is age
column 2 is gender
column 3...etc for 13 columns
There are 90 patients so 90 rows.
Here is the start
file = uigetfile ('.csv');
table = readtable(file);
t = cell2mat(table2cell(table));
Then I assume I create variables from that matrix :
age = t(:,1);
gender = t(:,2);
chest_pain_type = t(:,3);
Here is where I get stuck. Also there are two possible outcomes T or F
patient_outcome = '';
for this_row = t.' %what do i do here i tried
if (chest_pain_type>3) & (serum_cholestoral>0) & (st_depression>0.8) & (gender>0)
patient_outcome = 'T';
elseif (chest_pain_type>3) & (serum_cholestoral>0) & (st_depression>0.8) & (gender<=0) & (heart_condition>3)
patient_outcome = 'T';
elseif (chest_pain_type>3) & (serum_cholestoral>0) & (st_depression>0.8) & (gender<=0) & (heart_condition<=3) & (exercise_induced_angina>0)
patient_outcome = 'F';
end
end
Lastly then I want it to make a list of the outcomes for each patient (row) either T or F.
  4 个评论
Rik
Rik 2020-12-3
You can edit your question to put back the original title and content (and add the csv you attached to the comment you deleted).
Deleting things and changing the username is not generally an indication of good intentions, so go ahead and prove my cynicism wrong.

请先登录,再进行评论。

采纳的回答

Image Analyst
Image Analyst 2020-12-1
Attach a CSV file so we can get started helping you. In the meantime, you probably want to do something like
numRows = height(t); % or size(t, 1)
patient_outcome = false(numRows, 1);
for row = 1 : numRows
if (chest_pain_type(row)>3) &&&& (serum_cholestoral(row)>0) && (st_depression(row)>0.8) && (gender(row)>0)
patient_outcome(row) = true;
elseif (chest_pain_type(row)>3) && (serum_cholestoral(row)>0) && (st_depression(row)>0.8) && (gender(row)<=0) && (heart_condition(row)>3)
patient_outcome(row) = true;
elseif (chest_pain_type(row)>3) && (serum_cholestora(row)l>0) && (st_depression(row)>0.8) && (gender(row)<=0) && (heart_condition(row)<=3) && (exercise_induced_angina(row)>0)
patient_outcome(row) = false;
end
end

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Text Data Preparation 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by