Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

MATLAB HELP!! NOT C++ MATLAB has multiple built-in datasets that could be used f

ID: 3797717 • Letter: M

Question

MATLAB HELP!! NOT C++

MATLAB has multiple built-in datasets that could be used for data processing and analysis. One of those datasets is “hospital.mat” which contains simulated hospital data. Run the following snippet code to load the data and get enveloping information about the fields in the data.

load hospital

summary(hospital)

Your goals in this problem are to write MATLAB codes to:

1. Obtain the number of male patients and the number of female patients in the dataset. Compare your results to the ones obtained when you run “summary(hospital)”.

2. Obtain the number of smokers and non-smokers in the dataset. Again compare your results to the ones obtained when you run “summary(hospital)”.

3. Compute the average age of the female patients and the average age of the male patients.

4. Compute the average weight of the female patients and the average weight of the male patients.

5. Compute the average weight for the female patients that are smoker and have an age below 45.

6. Compute for each patient the mean of the number of trials and add the results to the table with a column header of Mean_Trials. For the patients that have missing number of trials, replace the NaN values with 0.

7. A blood pressure less than 120/80 mmHg is normal. A blood pressure of 140/90 mmHg or more is too high. People with levels in between 120/80 and 140/90 have a condition called prehypertension, which means they are at high risk for high blood pressure. Given this information, how many patients in the provided data have a normal blood pressure, a too high blood pressure, or have the prehypertension condition?

8. Compute the average blood pressure for the smoker and nonsmoker patients. Which group is the healthiest? Justify your answer.

Explanation / Answer

Solution :

clc;

close all;

clear all;

load hospital.mat;

%%Program starts here

%% Part 1

male=0;

female=0;

age_sum_male=0;

age_sum_female=0;

weight_sum_male=0;

weight_sum_female=0;

sex=hospital(:,2);

age=hospital(:,3);

age=double(age);

weight=double(hospital(:,4));

for i=1:100;

a=cellstr(sex(i,1));

if (strcmp(a,'Male'))

male=male+1;

age_sum_male=age_sum_male+age(i,1);

weight_sum_male=weight_sum_male+weight(i,1);

  

elseif (strcmp(a,'Female'))

female=female+1;

age_sum_female=age_sum_female+age(i,1);

weight_sum_female=weight_sum_female+weight(i,1);

end

end

disp('The number of male are:')

disp(male)

disp('The number of female are:')

disp(female)

summary(hospital);

%% Part 2

smoker=0;

nonsmoker=0;

smoker_data=hospital(:,5);

smoker_data=double(smoker_data);

for i=1:100;

a=(smoker_data(i,1));

if (a==1)

smoker=smoker+1;

elseif (a==0)

nonsmoker=nonsmoker+1;

end

end

disp('The number of smoker are:')

disp(smoker)

disp('The number of non-smoker are:')

disp(nonsmoker)

%% Part 3

disp('Average Age of Male Patient :')

disp(age_sum_male/male);

disp('Average Age of Female Patient :')

disp(age_sum_female/female);

%% Part 4

disp('Average Weight of Male Patient :')

disp(weight_sum_male/male);

disp('Average Weight of Female Patient :')

disp(weight_sum_female/female);

%% Part 5

count=0;

smoke_weight=0;

for i=1:100;

s=(smoker_data(i,1));

m=cellstr(sex(i,1));

a=double(age(i,1));

if (s==1)&&(strcmp(m,'Female'))&&(a<45)

count=count+1;

smoke_weight=smoke_weight+weight(i,1);

end

end

disp('Average Weight of female smoker whose age is below 45')

disp(smoke_weight/count);

%%

OUTPUT

The number of male are:

47

The number of female are:

53

Dataset array created from the data file hospital.dat.

The first column of the file ("id") is used for observation names. Other

columns ("sex" and "smoke") have been converted from their original coded

values into categorical and logical variables. Two sets of columns ("sys"

and "dia", "trial1" through "trial4") have been combined into single variables

with multivariate observations. Column headers have been replaced with more

descriptive variable names. Units have been added where appropriate.

LastName: [100x1 cell string]

Sex: [100x1 nominal]

Female Male

53 47

Age: [100x1 double, Units = Yrs]

min 1st quartile median 3rd quartile max

25 32 39 44 50

Weight: [100x1 double, Units = Lbs]

min 1st quartile median 3rd quartile max

111 130.5 142.5 180.5 202

Smoker: [100x1 logical]

true false

34 66   

BloodPressure: [100x2 double, Units = mm Hg]

Systolic/Diastolic

min 109 68

1st quartile 117.5 77.5

median 122 81.5

3rd quartile 127.5 89

max 138 99

Trials: [100x1 cell, Units = Counts]

From zero to four measurement trials performed

The number of smoker are:

34

The number of non-smoker are:

66

Average Age of Male Patient :

38.9149

Average Age of Female Patient :

37.7170

Average Weight of Male Patient :

180.5319

Average Weight of Female Patient :

130.4717

Average Weight of female smoker whose age is below 45

131.6000