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