Introduction to Matlab tutorials



Introduction to Matlab tutorials

Some excellent tutorials to help you get started with Matlab are below. If you have never worked with Matlab before, watch some of these short 5 – 8 minute tutorials and save yourself a lot of time. Also, with many of these videos, all the information you need to know is in the first half of the video (becoming more complicated and advanced in the later half), and the things you will learn overlap with other videos. Watch the first half and give it a try, and watch it again if necessary.

Getting started with Matlab: Start here!

Writing a Matlab program: How to create a program (.m file) file. You will need to do this to save the code that you will use to perform your analysis and should definitely watch this.

Working in the development environment: Better understand the parts of the Matlab interface that you can use. Not critical to working with Matlab but if you want to use the Matlab interface like a pro, give it a look over!

Analyzing data: How to quickly look at your data, plot it, and perform basic analysis. Learn how to perform an FFT.

Interactively creating plots: How to work more effectively with your plots, adding titles and labels, modifying axes, adding multiple sets of data, making plot arrays, etc.

Importing data from files: More advanced information about importing data.

Working with arrays: This is important to understand as all of our data will be in arrays, however basic array functions are covered in the Getting started video as well.

Matlab code segments and tips:

Set the current directory to the folder that your data is in. The ‘Current Directory’ is at the top and center of the Matlab interface. Select ‘…’ to change your directory.

The code that follows below will get you started on this assignment and accomplish many things you need to do. Comments are included throughout so you know what each section of the code does and know which things you might need to change. You can make two different Matlab program (*.m files) which will accomplish the different parts of the analysis (stabilogram and jumping), or you can make one program using different variable names, OR you can make one program with all this code in it and just comment out (using a % symbol) the parts you will not be using. Or you can just make up some code on your own!

%%IMPORTANT%% Before utilizing any sections of this code, you must first comment out the portions of your text data files that are not numbers. This means that you should open up your *.txt data file and put a % symbol at the start of each line that is not numbers and then save the modified file. ALSO, you may need to alter this code by

% Close figures and clear out other variables that have been assigned

close all;

clear all;

% Select the data file to load

ask = uigetfile('*.txt','Select the file to open');

data = load(ask);

% Assign vector quantities to the acquired data. DON'T FORGET SEMICOLONS at the end to suppress data output to the screen.

time = data(:,1); % Time data is all the data (indicated by : ) of column 1

fx_v = data(:,2); % _v is used to indicate these are voltage data

fy_v = data(:,3);

fz_v = data(:,4);

Mx_v = data(:,5);

My_v = data(:,6);

Mz_v = data(:,7);

% Force plate scaling factors in N or N-m/V

Fx_sf = 1000; % N/V (good to document the units when you code!!)

Fy_sf = 1000; % N/V

Fz_sf = 2000; % N/mV

Mx_sf = 600; % N-m/V

My_sf = 400; % N-m/V

Mz_sf = 300; % N-m/V

% Convert data to N and N-m using the scaling factor

t = time; % seconds

fx = fx_v.*Fx_sf; % N

fy = fy_v.*Fy_sf; % N

fz = fz_v.*Fz_sf; % N

Mx = Mx_v.*Mx_sf; % N-m

My = My_v.*My_sf; % N-m

Mz = Mz_v.*Mz_sf; % N-m

% BALANCE DATA

%Determine r_x and r_y to center of pressure

xp = -My./fz; % meters

yp = Mx./fz; % To divide vectors element by element, you need a ./

figure; plot(yp,xp) % Figure 8 below

title('Stabilogram'); xlabel('Side to side'); ylabel('Anterior-Posterior');

% You should also change your axis scales to be the same so that it is easier to see which direction the greatest sway was in, and center the position to zero. Matlab also can perform statistical analysis (i.e. does forward/backward or side-to-side sway vary more?).

[pic]

Figure 8: Balance stabilogram. You should make sure your axis have the same scale and center the position at zero.

%% JUMPING DATA

figure; plot(t,fz) % Look at a plot of fz and find an appropriate time to assess what the mass is. Figure not shown. Mass should be determined at a time when subject is stationary (i.e. fz is relatively constant) or alternately from averaging a couple data points.

g = 9.8; % m/s^2

mass = fz(1)/g; % kg, determine what the body mass is prior to the jump. You might need to change 1 to another data position if you are not standing stationary on the force plate when data acquisition begins

accel = (1/mass)*(fz-mass*g); % Calculate acceleration by solving Newtons second law: sum of forces on body equals mass * acceleration

velocity = cumtrapz(t,accel); % The function Z = cumtrapz(X,Y) integrates Y with respect to X using trapezoidal integration. Use Matlab Help Menu to learn more about this function. There are also other integration methods you could use.

figure; % Figure 9 below

subplot(3,1,1); plot(t,fz) % Create a new figure with subplots so it is easy to look at what time take-off and landing occurred. You could also make an overlay plot with two different axis.

title('Force'); xlabel('Time (sec)'); ylabel('Fz (N)');

subplot(3,1,2); plot(t,accel)

title('Acceleration'); xlabel('Time (sec)'); ylabel('accel (m/s^2)');

subplot(3,1,3); plot(t,velocity)

title('velocity'); xlabel('Time (sec)'); ylabel('velocity (m/s)');

% You must label time of take-off, landing, and peak height on your plot.

[pic]

Figure 9: Vertical force, acceleration, and velocity during a standing vertical jump.

% Load the Mocap data. Select the data file to load.

ask2 = uigetfile('*.trc','Select the file to open');

data2 = load(ask2);

% Assign vector quantities to the data

time = data2(:,2);

zpos_mocap = data2(:,5);

% Plot Mocap position data and determine max jump height

figure; plot(time,zpos_mocap)

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download