I am trying to read values from an excel csv file using 89 patient's data with the 13 variables show. I then use if else statements and a decision tree to decide if patient has heart disease. I am having trouble using csvread and am unsure of how to get this piece of code to work. I have been told i should use a matrix to help. Any suggestions on how I could fix this code
data = csvread('C:\Users\User\Documents\Signal processing\testData CW1.csv');
for i = 1:89
patient_Age = data(i,1);
patient_Gender = data(i,2);
patientChestPain = data(i,3);
patientRestingBP = data(i,4);
Serum_Cholestorol = data(i,5);
Fasting_BloodSugar = data(i,6);
Resting_ECG = data(i,7);
maximum_HR = data(i,8);
exercise_Angina = data(i,9);
ST_Depression = data(i,10);
ST_Slope = data(i,11);
flouro_Results = data(i,12);
heart_Condition = data(i,13);
end

댓글 수: 1

Bhaskar R
Bhaskar R 2019년 11월 19일
Use importdata or readtable commands for the better extraction of the data

댓글을 달려면 로그인하십시오.

답변 (1개)

Philippe Lebel
Philippe Lebel 2019년 11월 19일

1 개 추천

You are over writing the variables each loop!
I'd do it this way:
data = csvread('C:\Users\User\Documents\Signal processing\testData CW1.csv');
patient_Age = data(:,1);
patient_Gender = data(:,2)
patientChestPain = data(:,3);
...

댓글 수: 4

Eddie Burns
Eddie Burns 2019년 11월 19일
Thanks,
I am getting this error message
Operands to the || and && operators must be convertible to logical scalar values.
Philippe Lebel
Philippe Lebel 2019년 11월 19일
what code generates this error (copy-paste please)
Eddie Burns
Eddie Burns 2019년 11월 19일
if patient_ChestPain >3 && Serum_Cholestorol <=0
disp("Patient has heart disease")
elseif patient_ChestPain >3 && Serum_Cholestorol >0 && ST_Depression >0.8 && ST_Slope >1
disp("Patient has heart disease")
.......
it's because now you have lists containing 89 data each.
for i = 1:length(patient_Age)
if (patient_ChestPain(i) >3) && (Serum_Cholestorol(i) <=0)
disp("Patient has heart disease")
elseif (patient_ChestPain(i) >3) && (Serum_Cholestorol(i) >0) && (ST_Depression(i) >0.8) && (ST_Slope(i) >1)
disp("Patient has heart disease")
end
end

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Biological and Health Sciences에 대해 자세히 알아보기

제품

릴리스

R2017b

질문:

2019년 11월 19일

댓글:

2019년 11월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by