Create a MATLAB script that will perform the following funct

Create a MATLAB script that will perform the following functions: 1. Load the data from file normtemp.txt • First, load all three columns of data into a matrix X • The data is arranged in columns as follows: temperature, sex, age • Then, create a matrix variable temp for just the first column of X, which is the temperature 2. Generate a histogram with 12 bins • Label the x-axis ‘Temperature’ • Label the y-axis ‘Frequency’ • The title should be ‘Temperature for Adult Males and Females’


Now explore MATLAB’s built-in functions to calculate the following quantities for the temperature data. • mean(vector) • median(vector) • mode(vector) • var(vector) • std(vector) Write a function called mystat.m that takes a vector of data and prints out all these descriptive statistics functions applied to the vector of data, and the length of the data vector. Run your function on the temp vector.

Use the code below to take a sample of the total data set and compare it with the results from (3) above M=1; for N = 1:5:length(temp) sample(M) = temp (N); M = M + 1; end • Create a histogram with 12 bins for this data

Plot separate boxplots of all the ages of the males of the females

Add the required code to determine and print to the screen statistical quantities related to the “age” data in normtemp.dat

normtemp.txt:

Solution

clc;
clear all;
fileID = fopen(\'normtemp.txt\',\'r\');
format_spec=\'%f\';
A=fscanf(fileID,format_spec);
for i=0:((numel(A)/3)-1)
for j=1:3
X(i+1,j)=A(3*i+j);
end
end
fclose(fileID);
temp=X(:,1);
figure(1)
hist(temp,12);
xlabel(\'Temperature\');
ylabel(\'Frequency\');
title(\'Temperature for Adult Males and Females\');
disp(\'Status of Temperature Data\');
mystat(temp);

M=1;
for N = 1:5:length(temp)
sample(M) = temp (N);
M = M + 1;
end
disp(\'Status of Sample Data\');
mystat(sample);
figure(2)
hist(sample,12);
xlabel(\'Temperature\');
ylabel(\'Frequency\');
title(\'Temperature Sample for Adult Males and Females\');

% Cosidering Male have sex =1 and female sex=2
male_temp=X((X(:,2)==1),3);
female_temp=X((X(:,2)==2),3);
sex_data=[male_temp female_temp];
figure(3)
boxplot(sex_data);
title(\'Box plot of AGE According to Sex : (Male=1 , Female=2)\');
xlabel(\'Sex (Male=1 , Female=2)\');
ylabel(\'AGE of Person\');

Create a MATLAB script that will perform the following functions: 1. Load the data from file normtemp.txt • First, load all three columns of data into a matrix
Create a MATLAB script that will perform the following functions: 1. Load the data from file normtemp.txt • First, load all three columns of data into a matrix

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site