readMatrix/for loop issue
Mostra commenti meno recenti
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');
1 Commento
Please return to the original Q? that Walter gave guidance for --
What Walter suggested was to turn your code into a function named thisthrow and pass the input data to it by row.
The note by Harry is definitely true; looks like you may intend some ORs in there instead of all ANDs. On going back to original, I see the same logic therein; just the name change appears to be all.
I noticed it but hadn't tried to make sense out of it as I was trying to see about building the logic tree...it could be possible to first select for <=3 and then subset that to <=1, but not with the logic as written as AND--those that are <=1 are also <=3 so both are true which leads, I suspect, to a result not what is intended with the compound comparison.
Also, you want '&' here, not '&&'
Risposta accettata
Più risposte (1)
dpb
il 7 Dic 2020
0 voti
MATLAB is case sensitive--the function is readmatrix, not readMatrix
Categorie
Scopri di più su Matrix Indexing in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!