I'm having issues with reading in data and using the for loop. I need the code to read in 90 rows of 13 different parameters of data from a .csv file and understand that each row is one set of data and assign the correct variable to the correct value so that it can then use this to run the decision tree and give me an outcome for each row.
I am using Matlab R2018b version.
This is the piece of code I am using
myData = readmatrix('BME501_Coursework_Testdata.csv'); for i = 1 : size(myData,1) thisrow = myData(i,:); if Chest_Pain_Type <=3 && Induced_Angina <=0 && Age <=55 && Chest_Pain_Type <=1 && Gender <=0 Patient0utput = 0;elseif Chest_Pain_Type <=3 && Induced_Angina <=0 && Age <=55 && Chest_Pain_Type <=1 && Gender >0 && Resting_ECG <=1 && Chest_Pain_Type <=46 Patient0utput = 1;elseif Chest_Pain_Type <=3 && Induced_Angina <=0 && Age <=55 && Chest_Pain_Type <=1 && Gender >0 && Resting_ECG <=1 && Chest_Pain_Type >46 Patient0utput = 0;elseif Chest_Pain_Type <=3 && Induced_Angina <=0 && Age <=55 && Chest_Pain_Type <=1 && Gender >0 && Resting_ECG >1 Patient0utput = 0; elseif Chest_Pain_Type <=3 && Induced_Angina <=0 && Age <=55 && Chest_Pain_Type >1 Patient0utput = 0;elseif Chest_Pain_Type <=3 && Induced_Angina <=0 && Age >55 && Resting_ECG <=0 Patient0utput = 1;elseif Chest_Pain_Type <=3 && Induced_Angina <=0 && Age >55 && Resting_ECG >0 && Gender <=0 Patient0utput = 0;elseif Chest_Pain_Type <=3 && Induced_Angina <=0 && Age >55 && Resting_ECG >0 && Gender >0 && Resting_ECG <=0 && Chest_Pain_Type <=1 Patient0utput = 1;elseif Chest_Pain_Type <=3 && Induced_Angina <=0 && Age >55 && Resting_ECG >0 && Gender >0 && Resting_ECG <=0 && Chest_Pain_Type >1 && Resting_BP <=128 && Max_HR <=142 Patient0utput = 1;elseif Chest_Pain_Type <=3 && Induced_Angina <=0 && Age >55 && Resting_ECG >0 && Gender >0 && Resting_ECG <=0 && Chest_Pain_Type >1 && Resting_BP <=128 && Max_HR >142 Patient0utput = 0;elseif Chest_Pain_Type <=3 && Induced_Angina <=0 && Age >55 && Resting_ECG >0 && Gender >0 && Resting_ECG <=0 && Chest_Pain_Type >1 && Resting_BP >128 Patient0utput = 0;elseif Chest_Pain_Type <=3 && Induced_Angina <=0 && Age >55 && Resting_ECG >0 && Gender >0 && Resting_ECG >0 && Resting_ECG <=1 Patient0utput = 1;elseif Chest_Pain_Type <=3 && Induced_Angina <=0 && Age >55 && Resting_ECG >0 && Gender >0 && Resting_ECG >0 && Resting_ECG >1 && Fluoroscopy_Vessels <=0 && Resting_ECG <=271 Patient0utput = 0;elseif Chest_Pain_Type <=3 && Induced_Angina <=0 && Age >55 && Resting_ECG >0 && Gender >0 && Resting_ECG >0 && Resting_ECG >1 && Fluoroscopy_Vessels <=0 && Resting_ECG >271 Patient0utput = 1;elseif Chest_Pain_Type <=3 && Induced_Angina <=0 && Age >55 && Resting_ECG >0 && Gender >0 && Resting_ECG >0 && Resting_ECG >1 && Fluoroscopy_Vessels >0 Patient0utput = 1;elseif Chest_Pain_Type <=3 && Induced_Angina >0 && ST_Slope <=1 Patient0utput = 0;elseif Chest_Pain_Type <=3 && Induced_Angina >0 && ST_Slope >1 Patient0utput = 1;elseif Chest_Pain_Type >3 && Serum_Cholesterol <=0 Patient0utput = 1;elseif Chest_Pain_Type >3 && Serum_Cholesterol >0 && ST_Depression <=0.8 && Gender <=0 && Induced_Angina <=0 Patient0utput = 0;elseif Chest_Pain_Type >3 && Serum_Cholesterol >0 && ST_Depression <=0.8 && Gender <=0 && Induced_Angina >0 && Resting_ECG <=0 Patient0utput = 1;elseif Chest_Pain_Type >3 && Serum_Cholesterol >0 && ST_Depression <=0.8 && Gender <=0 && Induced_Angina >0 && Resting_ECG >0 Patient0utput = 0;elseif Chest_Pain_Type >3 && Serum_Cholesterol >0 && ST_Depression <=0.8 && Gender >0 && Fluoroscopy_Vessels <=0 && Heart_Condition <=3 Patient0utput = 0;elseif Chest_Pain_Type >3 && Serum_Cholesterol >0 && ST_Depression <=0.8 && Gender >0 && Fluoroscopy_Vessels <=0 && Heart_Condition >3 Patient0utput = 1;elseif Chest_Pain_Type >3 && Serum_Cholesterol >0 && ST_Depression <=0.8 && Gender >0 && Fluoroscopy_Vessels >0 Patient0utput = 1;elseif Chest_Pain_Type >3 && Serum_Cholesterol >0 && ST_Depression >0.8 && Gender <=0 && Heart_Condition <=3 && Induced_Angina <=0 Patient0utput = 0;elseif Chest_Pain_Type >3 && Serum_Cholesterol >0 && ST_Depression >0.8 && Gender <=0 && Heart_Condition <=3 && Induced_Angina >0 Patient0utput = 1;elseif Chest_Pain_Type >3 && Serum_Cholesterol >0 && ST_Depression >0.8 && Gender <=0 && Heart_Condition >3 Patient0utput = 1;else Patient0utput = 1; end if Patient0utput <1 disp 'This patient does not have cardiovascular disease';else disp 'This patient has cardiovascular disease'; end end
I was told to use thisrow in the decision tree but where do I put this in?
This is the error that comes up when i go to run the code
Undefined function or variable 'readMatrix'.Error in Testing (line 1) myData = readMatrix('BME501_Coursework_Testdata.csv');
Best Answer