Question
MatLab AddNoiseData.m %% Script to read in 2D array of grade data % Also provides column names dataN = csvread('DataClass.csv'); strColumns = {'LabQuiz', 'zyBooks', ...
MatLab
AddNoiseData.m
%% Script to read in 2D array of grade data
% Also provides column names
dataN = csvread('DataClass.csv');
strColumns = {'LabQuiz', 'zyBooks', ...
'Labs', 'Homeworks', ...
'MidtermI', 'MidtermII', 'Final', ...
'ExamAverage', 'Grade'};
% Line styles
strLineStyles = {'--b', ':b', '-k', '--k', ':g', '--g', '.g', '-g', '-r'};
%% Add noise to the data (+- 1) and write it out
% rand generates a 2D array of noise in the range of 0 to 1
% shift and scale
noise = 2 * (rand( size(dataN) ) - 1.0);
dataN = dataN + noise;
csvwrite('DataClassWithNoise.csv', dataN)
Already finish problem 1, need help for problem 2.
Problem 1
Plot last years ENGR112 data by type.
Deliverables:
Plot of data
Each type of data
Lines for grade divisions (70, 80, 90)
Legend
Script
Command window output
Step by Step Instructions:
Start a new script and copy the first lines from AddNoiseData.m (the ones that read in the data and create the string arrays that say what the column headers are and provide colors for the plot.
Run and make sure that you are reading data correctly what size is dataN?
Plot one column of data
colData = dataN(:, 1); % Gets the first column of the data
What happens if you just plot it? Try plotting it with markers
You want sort().
Sort the data and plot it.
In this case you dont need to make a dependent variable t. You can just call plot( colData, -b) and it will default to plotting 0, 1, 2, etc
Wrap the code for the bit above in a for loop
Remember that size( dataN, 2 ) will give you the number of columns to plot over
Remember to change 1 to your loop index variable
Pretty colors
You can use the strLineStyles to set a different color for each plot. Remember to use {}
You can use the strColumns in the legend as-is; to put the legend in the upper left hand corner, use the Location option (google matlab legend).
Adding the horizontal stripesUse a for loop to plot one stripe at 70, one at 80, one at 90. Remember that the x values start at 0 and go to the number of students == number of rows.
plot( [xStart, xEnd], [height, height], -r );
Problem 2
Print out the following statistics from the data in problem 1:
Number of students who did better on the labs than the homeworks
Number of students who did better on the homeworks than the final exam
Average score for each category
[Extra credit] Average difference between labs & homeworks and homeworks & final exam
[Extra credit] Do the number counts with relational operators. You can calculate those numbers with a single line of code
Deliverables:
Script for calculating the above
Command window output
Must use for loops
Step by Step Instructions:
Copy the first few lines from your Lab 1 problem (reading dataN and the strColumns)
Printing out the means of each columnThere are two ways to do this:
One is to call mean with the entire matrix (refer to help on mean to see what will happen when you do this
Use the colon operator to get out all of the elements for the column IN the for loop and then call mean on that (column) array.
Either way youll need a for loop that goes over each column (use size() command)
Use strColumns to print out the name of the column along with the mean
Note: The first method is more efficient.
Counting studentsFirst thing to do is declare an index variable for each of the columns youre interested in; that way, if they change later you dont have to re-write your code. Also makes it easier to read the code
indexLabColumn = 3;
Create a for loop that goes over each STUDENT this time (i.e., number of rows)
Make a counting variable, eg, betterLabThanHomework = 0;
Do just the homework score better than the lab score first. Hint: Youll need an if statement in the for loop
If youre struggling with either how to write the if or how to increment the counter variable, grab a TA
Add another if statement for the homeworks and exams
Extra credit IThis should look like mean( lab homework ) how do you get out ALL of the student lab scores all at once? Hint: colon operator
You should do this without a for loop for credit.
Extra credit IIThis should look like sum( lab > homework ) and like extra credit I you want to perform the comparison on ALL of the students all at once (not using a for loop)
lab > homework will return an ARRAY of zeros and ones, zeros for false, ones for true. Then just count the ones
Self-check:
Average 82.X4 for item LabQuiz
Average 135.X2 for item zyBooks
Average 93.X0 for item Labs
Average 91.X9 for item Homeworks
Average 80.X1 for item MidtermI
Average 75.X9 for item MidtermII
Average 65.X6 for item Final
Average 73.X9 for item ExamAverage
Average 86.X4 for item Grade
Number of people with lab scores higher than homeworks: 1X5
Average difference: 1.X0
Number of people with homework scores higher than final exam: 2X5
Average difference: 25.X3
Total number of students: 2X9
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started