Create MATLAB code that will run statistics (min,max,mean,mode) on a selected column (just 1 column, not all of them). For example, if I want to run the statistics on the column 'age', it will only run it on that column and not the others. The file is cardio_dataset and each column is separated by commas.
The sample file is the following:
age,gender,height,weight,sys_bp,dia_bp,cholesterol_lvl,gluc_lvl,smoke,alco,active,cardio
50.3917808219178,2,168,62,110,80,1,1,0,0,1,0
55.4191780821918,1,156,85,140,90,3,1,0,0,1,1
51.6630136986301,1,165,64,130,70,3,1,0,0,0,1
48.2821917808219,2,169,82,150,100,1,1,0,0,1,1
47.8739726027397,1,156,56,100,60,1,1,0,0,0,0
60.0383561643836,1,151,67,120,80,2,2,0,0,0,0
60.5835616438356,1,157,93,130,80,3,1,0,0,1,0
61.8739726027397,2,178,95,130,90,3,3,0,0,1,1
48.4054794520548,1,158,71,110,70,1,1,0,0,1,0
%matlab program
data = readtable('cardio_dataset.csv'); %read csv file
%choose column name to perform statistics operation
disp("1.age")
disp("2.gender")
disp("3.height")
disp("4.weight")
disp("5.sys_bp")
disp("6.dia_bp")
disp("7.cholesterol_lvl")
disp("8.gluc_lvl")
disp("9.smoke")
disp("10.alco")
disp("11.active")
disp("12.cardio")
choice = input("Enter a column name to perfrom operations:");
%switch case will according to choice
switch choice
case 1
disp("age")
Min = min(data.age)
Max = max(data.age)
Mean = mean(data.age)
Mode =mode(data.age)
case 2
disp("gender")
Min = min(data.gender)
Max = max(data.gender)
Mean=mean(data.gender)
Mode=mode(data.gender)
case 3
disp("height")
Min = min(data.height)
Max = max(data.height)
Mean= mean(data.height)
Mode= mode(data.height)
case 4
disp("weight")
Min=min(data.weight)
Max=max(data.weight)
Mean=mean(data.weight)
Mode=mode(data.weight)
case 5
disp("sys_bp")
Min=min(data.sys_bp)
Max=max(data.sys_bp)
Mean=mean(data.sys_bp)
Mode=mode(data.sys_bp)
case 6
disp("dia_bp")
Min=min(data.dia_bp)
Max=max(data.dia_bp)
Mean=mean(data.dia_bp)
Mode=mode(data.dia_bp)
case 7
disp("cholesterol_lvl")
Min=min(data.cholesterol_lvl)
Max=max(data.cholesterol_lvl)
Mean=mean(data.cholesterol_lvl)
Mode=mode(data.cholesterol_lvl)
case 8
disp("gluc_lvl")
Min=min(data.gluc_lvl)
Max=max(data.gluc_lvl)
Mean=mean(data.gluc_lvl)
Mode=mode(data.gluc_lvl)
case 9
disp("smoke")
Min=min(data.smoke)
Max=max(data.smoke)
Mean=mean(data.smoke)
Mode=mode(data.smoke)
case 10
disp("alco")
Min=min(data.alco)
Max=max(data.alco)
Mean=mean(data.alco)
Mode=mode(data.alco)
case 11
disp("active")
Min=min(data.active)
Max=max(data.active)
Mean=mean(data.active)
Mode=mode(data.active)
case 12
disp("cardio")
Min=min(data.cardio)
Max=max(data.cardio)
Mean=mean(data.cardio)
Mode=mode(data.cardio)
otherwise
disp("Column is not present in the file")
end
Output::
Get Answers For Free
Most questions answered within 1 hours.