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 Multi-platform, Multi Format data importing Analysis Tools (Existing,Custom) Statistics Graphing Modeling

4 Data Acquisition » A framework for bringing live, measured data into MATLAB using PC-compatible, plug-in data acquisition hardware

5 Multi-platform, Multi Format data importing » Data can be loaded into Matlab from almost any format and platform » Binary data files (eg. REX, PLEXON etc.) » Ascii Text (eg. Eyelink I, II) » Analog/Digital Data files PC UNIX 100101010 Subject 1 143 Subject 2 982 Subject 3 87 …

6 Analysis Tools » A Considerable library of analysis tools exist for data analysis » Provides a framework for the design, creation, and implementation of any custom analysis tool imaginable

7 Statistical Analysis » A considerable variety of statistical tests available including: ˃TTEST ˃Mann-Whitney Test ˃Rank Sum Test ˃ANOVAs ˃Linear Regressions ˃Curve Fitting

8 Graphing » A Comprehensive array of plotting options available from 2 to 4 dimensions » Full control of formatting, axes, and other visual representational elements

9 Modeling » Models of complex dynamic system interactions can be designed to test experimental data

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

11

12 1 2

13 » Ordered set of numbers: (1,2,3,4) » Example: (x,y,z) coordinates of pt in space.

14 Vector Addition v w V+w

15 Scalar Product v av

16 » sum » max, min, mean, sort, … » Pointwise:.^

17 Inner (dot) Product v w  The inner product is a SCALAR!

18 Matrices Sum: A and B must have the same dimensions

19 Matrices Product: A and B must have compatible dimensions Identity Matrix:

20 Matrices Transpose: If A is symmetric

21 Matrices Determinant: A must be square ( n = m ) The area of the parallelogram is the absolute value of the determinant of the matrix formed by the vectors representing the parallelogram's sides. n = m = 2 n = m = 3 The volume of this Parallelepiped is the absolute value of the determinant of the matrix formed by the rows r1, r2, and r3.Parallelepiped r1 r2 r3

22 Matrices Inverse: A must be square

23 2D Translation t P P’P’P’P’

24 2D Translation Equation P x y tx ty P’P’P’P’ t

25 2D Translation using Matrices P x y tx ty P’P’P’P’ t tP

26 Scaling P P’P’P’P’

27 Scaling Equation P x y s.x P’P’P’P’ s.y

28 Stretching Equation P x y Sx.x P’P’P’P’ Sy.y

29 Rotation P P’P’P’P’

30 Rotation Equations Counter-clockwise rotation by an angle  P x y’y’y’y’ P’P’P’P’  x’x’x’x’ y

31 Properties of rotation matrixes R is a rotation matrix and it must satisfy the following constraints:

32 P x y y’y’ x’x’

33 Navigating the Matlab Desktop Commonly Used Toolboxes

34 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. Variable = Expression **Variable Names are Case Sensitive! Ex. «a» and «A» are two different variables

35 Solving equations using variables Variable = Expression >> x = 6 x = 6 >> y = 2 y = 2 >> x + y ans = 8 >> x - y ans = 4 >> x * y ans = 12 >> x / y ans = 3 >> x ^ y ans = 36 Basic Calculation Operators: + Addition -Subtraction Multiplication / Division ^ Exponentiation Reserved variables ! They are special names used to indicate either a specific number (e.g. pi, inf, eps, …), a keyword (e.g. char, double, …), or the result of an expression (ans). By default they have a specific meaning or value, if you assign a new expression to these names, you cannot use the default reserved variable anymore during the current session of Matlab.

36 Working with Matrices Matlab works with rectangular numerical matrixes A matrix is a collection of numerical values that are organized into a specific configuration of rows and columns. The number of rows and columns can be any number Example 3 rows and 4 columns define a 3 x 4 matrix having 12 elements

37 Working with Matrices Matlab works with rectangular numerical matrixes A matrix is a collection of numerical values that are organized into a specific configuration of rows and columns. The number of rows and columns can be any number Example 3 rows and 4 columns define a 3 x 4 matrix having 12 elements A scalar is a single number and is represented by a 1 x 1 matrix in matlab. A vector is a one dimensional array of numbers and is represented by an n x 1 column vector or a 1 x n row vector of n elements

38 Working with Matrices c = 5.66 or c = [5.66] c is a scalar or a 1 x 1 matrix

39 Working with Matrices c = 5.66 or c = [5.66] c is a scalar or a 1 x 1 matrix x = [ 3.5, 33.22, 24.5 ] x is a row vector or a 1 x 3 matrix

40 Working with Matrices c = 5.66 or c = [5.66] c is a scalar or a 1 x 1 matrix x = [ 3.5, 33.22, 24.5 ] x is a row vector or a 1 x 3 matrix x1 = [ 2 5 3 -1] x1 is column vector or a 4 x 1 matrix

41 Working with Matrices c = 5.66 or c = [5.66] c is a scalar or a 1 x 1 matrix x = [ 3.5, 33.22, 24.5 ] x is a row vector or a 1 x 3 matrix x1 = [ 2 5 3 -1] x1 is column vector or a 4 x 1 matrix A = [ 1 2 4 2 -2 2 0 3 5 5 4 9 ] A is a 4 x 3 matrix

42 Working with Matrices Spaces, commas, and semicolons are used to separate elements of a matrix

43 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]

44 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

45 Working with Matrices Colon operator identifies a range of values: [ 1 : 3 ] = [ 1, 2, 3] [ 1 : 2: 9 ] = [ 1, 3, 5, 7, 9] [ 5 : -1: 1 ] = [ 5, 3, 1] B = [1:4 ; 5:8 ; 9,8,7,6 ] = A 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] start jump end

46 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(4,1)=5

47 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(4,1)=5 Example: >> A = [1 2 4 5;6 3 8 2] A is a 4 x 2 matrix >> A(1,2) ans = 6 The colon operator can be used to index a range of elements >> A(1:3,2) ans = 1 2 4

48 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]

49 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 HELP! b = zeros(1,5) b = [0 0 0 0 0]

50 Data Types and Formats The semicolon operator determines whether the result of an expression is displayed who lists all of the variables in your matlab workspace whos list the variables and describes their matrix size

51 Saving your Work To save data to a *.mat file: Typing ‘save filename’ at the >> prompt and the file ‘filename.mat’ will be saved to the working directory Select Save from the file pull down menu Automatically, all the variables in the workspace will be stored in the same mat-file named filename.mat. To reload a *.mat file Type ‘load filename’ at the >> prompt to load ‘filename.mat’ (ensure the filename is located in the current working directory) 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

52 Using functions Matlab has a wide variety of toolboxes, whithin each toolbox you can find several type of functions specific for that topic. Some functions are generic and you can find them in the MATLAB TOOLBOX. RESULT: more or less, you can find any type of function you need. 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 just create an elaboration by using the available functions, or you can create your own function (see after).

53 Basic plotting commands FunctionDescription plot Graph 2-D data plot3 Graph 3-D data plot plot3 Help – Search – type plot and obtain the following explanation! plot(Y) plots the columns of Y versus the index of each value when Y is a real number. plot(X1,Y1,...,Xn,Yn) plots each vector Yn versus vector Xn on the same axes. If one of Yn or Xn is a matrix and the other is a vector, plots the vector versus the matrix row or column with a matching dimension to the vector. For example, plot a sinusoidal curve: » t = 0:1/100:1; » y = sin(2*pi*t); » plot(t,y); More advanced! plot3(t,t,y); grid on xlabel x ylabel y zlabel z B=repmat(y,length(t),1); mesh(t,t,B); Frequency of the sinusoidal curve

54 Enter the following Matrices in matlab using spaces, commas, and semicolons to separate rows and columns: A = B = C = D = E = a 5 x 9 matrix of 1’s

55 Use the who and whos functions directly from the Command Window to confirm all of the variables and matrices in the work space are present and correct A = B = C = D = E = a 5 x 9 matrix of 1’s

56 Change the following elements in each matrix: Now save all the variables in the workspace in a mat-file named myvar. A = B = C = D = 76 0 0 0

57 Create a variable named S, which contains two cycles of a sinusoidal curve of frequency 2Hz and resolution pi/10. Plot S in a two dimensional graph. Try to use the documentation to change from the solid blue line, to a dashed red line To modify these parameters you need to add a third option to the plot command. Prompt plot(t,y, ‘options’). Instead of using the word options, use the symbols that indicate the type and the color of the line click on the LineSpec link on the plot page documentation to see which are the symbols for the dashed line and for the red.LineSpec

58 » 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.

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

60 » Smoothing data using low pass filters » Normalizing (interpolating) data

61 » Smoothing data using low pass filters » Ex EMG signals Normalized for the average 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

62 » 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 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

63 Normalize from FS1 to FS2 in gait percentage the two signals relative to the Flexion/Extension angle at the hip joint. The variables stored in the mat-file hip_gait_data are relative to a patient A, and from hip_gait_data2 we have data from patient B. Once that both signals are normalized, plot them together in the same figure and with two different colors. Compute the Range of Motion for both signals (after normalization). Use the max and min functions to compute ROM.

64


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