Intro to Matlab - Bonus Assignment

Intro to Matlab - Bonus Assignment

Question 1

Assign values: x = 4, y = 8, and z = 10.
x = 4;
y = 8;
z = 10;
What is a = x + y + z?
a = x + y + z
a = 22
What is b = z - y?
b = z - y
b = 2

Question 2

Create an array (called "array1") of 4 numbers starting from 5 to 8. We use the “[“ to denote the start of a matrix and “]” to denote the end of the matrix.
array1 = [5:8]
array1 = 1×4
5 6 7 8
Find the value at a specific location in the array. What is the 3rd number of "array1"?
array1(3)
ans = 7
Find the maximum, mean, and standard deviation of "array1".
max(array1)
ans = 8
mean(array1)
ans = 6.5000
std(array1)
ans = 1.2910

Question 3

Create a 3 by 5 matrix called "matrix1". Specifically, create a matrix with three rows; first row from 1 to 5, second row from 11 to 15, third row 101 to 105 .
matrix1 = [1:5; 11:15; 101:105]
matrix1 = 3×5
1 2 3 4 5 11 12 13 14 15 101 102 103 104 105
Finding the size. What is the size of "matrix1" (rows, columns)?
size(matrix1)
ans = 1×2
3 5
Find the value at a specific location in "matrix1". What is the number in the 3rd row, 5th column?
matrix1(3,5)
ans = 105
Find the maximum, mean, and standard deviation of the second row of "matrix1".
max(matrix1(2,:))
ans = 15
mean(matrix1(2,:))
ans = 13
std(matrix1(2,:))
ans = 1.5811

Question 4 - Helmet Data

IMG-1571.gif
The data in this lab was collected using the impact pendulum in the Injury Prevention and Mobility Laboratory. This pendulum allows for consistent and reproducible impacts to be simulated. Attached to the pendulum is a Hybrid-III head and neck. Secured to the head is a hockey helmet which has a triaxial (x,y,z) GForceTracker sensor within the foam lining inside the helmet. The helmet sensor is sampled at 3,000 Hz.
These data are from a head impact (see video above of an example impact). The helmet data is a 40 ms recording. There are four columns of acceleration (units of g) and time (milliseconds), (x, y, z, and time)

Import the data ('helmet_time_data.txt') - make sure you are in the right directory (check directory and folder in main MATLAB window)

helmet_time_data = importdata('BPK/201/Bonus/helmet_time_data.txt');

Find size of data

[rows, cols] = size(helmet_time_data)
rows = 120
cols = 4

Create variables ( x, y, and z acceleration, and time ) from the data for the helmet senor

x = helmet_time_data(:,1);
y = helmet_time_data(:,2);
z = helmet_time_data(:,3);
time = helmet_time_data(:,4);

Calculate the resultant acceleration for the helmet senor

resultant = sqrt(x.^2 + y.^2 + z.^2);

Determine what the max resultant acceleration is for the helmet sensor, and index (find the row) where it occurs

[M, I] = max(resultant)
M = 20.6108
I = 65

Find the time at which the max acceleration occurs for the helmet sensors

t_max = time(I)
t_max = 21.3333

Plot the resultant acceleration vs time for the helmet sensor

plot(time, resultant)
title('Resultant Helmet Acceleration During Impact')
xlabel('Time (ms)')
ylabel('Acceleration (g)')