Presentation is loading. Please wait.

Presentation is loading. Please wait.

Matrix Laboratory Created in late 1970’s Intended for used in courses in matrix theory, linear algebra and numerical analysis Currently has grown into.

Similar presentations


Presentation on theme: "Matrix Laboratory Created in late 1970’s Intended for used in courses in matrix theory, linear algebra and numerical analysis Currently has grown into."— Presentation transcript:

1

2 Matrix Laboratory Created in late 1970’s Intended for used in courses in matrix theory, linear algebra and numerical analysis Currently has grown into an interactive system and high level programming language for general scientific and technical computation

3 Common Uses for Matlab in Research Data Acquisition Analysis Tools (Existing,Custom) Statistics Graphing Modeling

4 » Matlab interface » Variables and Expressions » Analysis and Visualizations with Vectors » and Matrices Is everything clear

5

6 You can change the desktop arrangement to meet your needs, including resizing, moving, and closing tools.

7 1 2

8

9 Solving equations using variables Expression language Expressions typed by the user are interpreted and evaluated by the Matlab system Variables are names used to store values Variable names allow stored values to be retrieved for calculations or permanently saved When MATLAB encounters a new variable name, it automatically creates the variable and allocates the appropriate amount of storage. Few simple rules for naming variables Variable = Expression (!!) Variable Names are Case Sensitive! Ex. «a» and «A» are two different variables (!!) Be careful not to overwrite values in your variable by accident!

10 Working with Matrices Spaces, commas, and semicolons are used to separate elements of a matrix Spaces or commas separate elements of a row [1 2 3 4] or [1,2,3,4] Semicolons separate columns A = [1,2,3,4;5,6,7,8;9,8,7,6] = [1 2 3 4 5 6 7 8 9 8 7 6] Colon operator identifies a range of values: B = [1:4 ; 5:8 ; 9,8,7,6 ] = A

11 Working with Matrices Colon operator identifies a range of values: [ 1 : 3 ] equivalent to [ 1, 2, 3] [ 1 : 2: 9 ] equivalent to [ 1, 3, 5, 7, 9] [ 5 : -1: 1 ] equivalent to [ 5, 4, 3, 2, 1] B = [1:4 ; 5:8 ; 9,8,7,6 ] equivalent to [1 2 3 4 5 6 7 8 9 8 7 6] start jump end

12 Indexing Matrices A m x n matrix is defined by the number of m rows and number of n columns An individual element of a matrix can be specified with the notation A(i,j) where the first number (i) indicates the first dimension of the matrix (the row), and the second indicates the columns Example: >> A = [1 2 4 5 6 3 8 2] >> A(2,1) ans = 6 The colon operator can be used to index a range of elements >> A(1:3,2) ans = 1 2 4

13 Indexing Matrices Specific elements of any matrix can be overwritten using the matrix index Example: A = [1 2 4 5 6 3 8 2] >> A(1,2) = 9 Ans A = [1 2 4 5 9 3 8 2]

14 Matrix Shortcuts The ones and zeros functions can be used to create any m x n matrices composed entirely of ones or zeros Example a = ones(2,3) a = [1 1 1 1 1 1] (!) if you need to understand more about how to use these functions, go to the online HELP! b = zeros(1,5) b = [0 0 0 0 0]

15 Saving your Work To save data to a *.mat file: Typing ‘save filename’ on the command window (>> prompt) and the file ‘filename.mat’ will be saved in the current folder (you can see it popping out in the list of files under the ‘current folder’ window) Or Select Save from the file pull down menu This command will store all the variables in the workspace in the same *.mat file named filename.mat. To reload a *.mat file Type ‘load filename’ on the command window (>> prompt) to load ‘filename.mat’ (ensure the filename is located in the current working directory) Or Select Open from the file pull down menu and manually find the data file (!) Again…to see all the options that are offered for a function, type doc namefunction (in this case doc save, or doc load) What is it? *.mat is the extension of data files in Matlab. They contain any type of variable that can be created in Matlab and that show up in the ‘current workspace’ window

16 Basic plotting commands figure Create figure graphics object hold on Retain current graph in figure axis tight Axis scaling and appearance

17 » What happens if I have to close Matlab because it’s time to go home??? ˃I lose all the work I did in the Command Window! ˃I lose all the variables I created during the current session of work.

18 » I can write the list of command, functions and variables in a new Script and then save it as file.m » When I need to run again that list of commands I reopen the stored file.m and I can continue my work!

19

20 Using functions: control flow functions for Execute statements specified number of times Syntax for index = values program statements … end Description repeatedly executes one or more MATLAB statements in a loop. values has one of the following forms: initval:endval initval:step:endval valArray

21 Using functions Matlab has a wide variety of toolboxes, whithin each toolbox you can find several types of function specific for that topic. Some functions are generic and you can find them under the generic MATLAB TOOLBOX. Therefore, you can find any type of function you need! If there is no specific function for what you want to do, you can create one by using the command function (check it out on the online HELP!) For a list of the elementary mathematical functions, type help elfun For a list of more advanced mathematical and matrix functions, type help specfun help elmat You can combine the available functions one after the other, or one inside the other (nesting).

22 Available data: 4 EMG signals (RF, BF, Gmed, TFL) @ 1000Hz MVC signals relative to the same muscles @ 1000Hz 3 ANGLES (hip flex/ext, hip abd/add, hip internal/external rotations) @ 200Hz start and end EVENTS (detected respect to the video/angles frequency) TO DO: verify the relationship between EMG and hip angles. What muscles are active when the hip is at maximum extension? Theoretical steps? Matlab steps?

23 Using functions: calculate the average mean Average or mean value of array Syntax M = mean(A) M = mean(A,dim) Description M = mean(A) returns the mean values of the elements along different dimensions of an array. If A is a vector, mean(A) returns the mean value of A. If A is a matrix, mean(A) treats the columns of A as vectors, returning a row vector of mean values. If A is a multidimensional array, mean(A) treats the values along the first non-singleton dimension as vectors, returning an array of mean values. M = mean(A,dim) returns the mean values for elements along the dimension of A specified by scalar dim. For matrices, mean(A,2) is a column vector containing the mean value of each row. Examples A = [1 2 3; 3 3 6; 4 6 8; 4 7 7]; mean(A) ans = 3.0000 4.5000 6.0000 mean(A,2) ans = 2.0000 4.0000 6.0000

24 Using functions: creating coefficients for filters butter Butterworth filter design Syntax [b,a] = butter(n,Wn) Description [b,a] = butter(n,Wn) designs an order n lowpass digital Butterworth filter with normalized cutoff frequency Wn. It returns the filter coefficients in length n+1 row vectors b and a, with coefficients in descending powers of z.

25 Using functions: filtering filter 1-D digital filter Syntax y = filter(b,a,X) Description y = filter(b,a,X) filters the data in vector X with the filter described by numerator coefficient vector b and denominator coefficient vector a. filtfilt Zero-phase digital filtering Syntax y = filtfilt(b,a,x) Description y = filtfilt(b,a,x) performs zero-phase digital filtering by processing the input data, x, in both the forward and reverse directions

26 Using functions: create linear intervals linspace Generate linearly spaced vectors Syntax y = linspace(a,b) y = linspace(a,b,n) Description The linspace function generates linearly spaced vectors. It is similar to the colon operator ":", but gives direct control over the number of points. y = linspace(a,b) generates a row vector y of 100 points linearly spaced between and including a and b. y = linspace(a,b,n) generates a row vector y of n points linearly spaced between and including a and b. For n < 2, linspace returns b.

27 Using functions: interpolating data spline Cubic spline data interpolation Syntax yy = spline(x,Y,xx) Description yy = spline(x,Y,xx) uses a cubic spline interpolation to find yy, the values of the underlying function Y at the values of the interpolant xx. For the interpolation, the independent variable is assumed to be the final dimension of Y with the breakpoints defined by x. Example x = 0:10; y = sin(x); xx = 0:.25:10; yy = spline(x,y,xx); plot(x,y,'o',xx,yy)

28 » Normalizing (interpolating) data » Ex. Express the gait signal in percentange of gait Cut the signal from FS1 to FS2 Interpolate the signal in 101 points to express it in percentage of gait cycle Work flow

29 » Normalizing (interpolating) data » Ex. Express the gait signal in percentange of gait Cut the signal from FS1 to FS2 Interpolate the signal in 101 points (n_norm) to express it in percentage of gait cycle y_cut = Hip_FEangle(FS1:FS2) x_base_norm = linspace(0,length(y_cut),n_norm) y_norm = spline(x_base_current, y_cut, x_base_norm) Work flowMatlab functions (!) Look at mygait.m in the folder

30 » Smoothing data using low pass filters » Ex EMG signals Remove the bias Rectify the signal (absolute value) Low pass filter Work flow

31 » Smoothing data using low pass filters » Ex EMG signals Remove the bias Rectify the signal (absolute value) Low pass filter EMG_m = mean( EMG ); EMG_n = EMG – EMG_m; EMG_r = abs( EMG_n ); [B,A] = butter(4,10/500); Z = filter( B, A, EMG_r); Work flowMatlab functions (!) Look at myemg.m in the folder

32 Useful links: http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-094- introduction-to-matlab-january-iap-2010/lecture-notes/ Only the first 2! http://www.mathworks.com/help/pdf_doc/matlab/getstart.pdf Very good introduction. Covers everything necessary to learn the basics http://eecourses.technion.ac.il/matlab/Matlab%20PDFs/using_ml.pdf More advanced


Download ppt "Matrix Laboratory Created in late 1970’s Intended for used in courses in matrix theory, linear algebra and numerical analysis Currently has grown into."

Similar presentations


Ads by Google