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

This Mini Project involves the creation of a structure that will hold a dataset

ID: 3209842 • Letter: T

Question

This Mini Project involves the creation of a structure that will hold a dataset and statistical information about the data set. First, let's describe the properties of our structure, Data. Data will have the following properties: values: an array of numbers in ascending order mean: the sample mean of all the numbers in value median: the sample median of all the numbers in value variance: the sample variance of all the nambers in value - Note that you can use any variable name for Data in the fellowing functions, but the properties described above MUST be spelled and capitalized EXACTLY as above in order for you to get the last part of this project running. In addition to this, the functions we ask you to write in this project must ave EXACTLY the names we ask for in order for the last part of this project to work. The last part is not for a grade, but it is fun for you. Part I: Data Structure Creation Function Create a function named createData. createData should take one imput: Anumber to start your data set off. It should output a data structure, as defined above. values, mean, and median will all be your input number. variance will be 0. Part 2: Adding New Numbers Create a function called addData. addbata should take two inputs in the following order -A data structure A new pumber to add to that data structure It should output the data structure, with the new number included in the array contained by the values property. The number should be incladed in such a way that the array in values will always be sorted in ascending order. You can assume that the array is already in ascending order when the data 35 7 91, and your structure is given as an input. For example, if the array in values was [1 input number was 6, the new array would be 11 356 79 Part 3: Updating Statistics Note that you must accomplish everything in this part of the Mini Project wirhot any built in functions that calculate means, medians, standard deviarions, or sums of arrays. There are quite a Jew functions in MATLAB that do tasks like this. They are all forbidden here. Yow should focus on using mathematical functions and operalors that work on one or two individwal nwmbers, loops, comditional statements, and array indexing Create a function called updateStats, updateStats should take one input: -A data structure It should output a data structure with a newly calculated values for the mean, median, and variance properties. See Appendix A for information on how to calculate these values You can use the built-in MATLAB functions mean, median, and var to check your answers, but again, do not use them in the function.

Explanation / Answer

ANSWER:

Here's the code

-----------------------------------------------------------------------------------------------------------------------------------------------------

% Data class for the data structure.
% It is inherited from handle class so as to save the changes made in any
% function
classdef Data < handle

%Properties(variables of the class
properties(Access=public)
values;
mean;
median;
variance;
end

% Methods for the class.
% Please note that you don't need to pass obj as a parameter while
% calling any function of the class. But it is included in the class
% declaration, as per Matlab syntax rules.
methods(Access=public)

% createData function
function obj = createData(obj, num)
obj.values = num;
obj.mean = num;
obj.median = num;
obj.variance = 0;
end

% addData function
function obj = addData(obj, num)
current_size = size(obj.values,2);
if(num <= obj.values(1))
obj.values = [num, obj.values];
elseif(num >= obj.values(current_size))
obj.values = [obj.values, num];
else
iter = 1;
for iter=1:current_size
if(obj.values(iter)<= num && obj.values(iter+1)>= num)
break;
end
end
obj.values = [obj.values(1:iter),num, obj.values(iter+1:current_size)];
end
end

% updateStats function
function obj = updateStats(obj)
current_size = size(obj.values,2);
sum = 0;
for i=1:current_size
sum=sum+obj.values(i);
end
obj.mean = sum/current_size;

if( mod(current_size,2) ==0)
obj.median = (obj.values(current_size/2) + obj.values((current_size/2)+1))/2;
else
obj.median = obj.values(floor(current_size/2));
end

var_sum = 0;
for i=1:current_size
var_sum = var_sum + (obj.values(i)-obj.mean).*(obj.values(i)-obj.mean);
end
obj.variance = (var_sum/current_size);
end
end
end

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote