MATLAB Introduction Ron Ilizarov Application Engineer 1
What is MATLAB? High-level language Interactive development environment Used for: Numerical computation Data analysis and visualization Algorithm development and programming Application development and deployment 2
Technical Computing Workflow Access Files Explore & Discover Data Analysis & Modeling Share Reporting and Documentation Software Algorithm Development Outputs for Design Code & Applications Hardware Application Development Deployment Automate 3
Accessing Data from MATLAB Access Explore & Discover Share Files Excel, text, or binary Audio and video, image Scientific formats and XML Applications and languages C/C++, Java, FORTRAN COM,.NET, shared libraries Databases (Database Toolbox) Measurement hardware Data acquisition boards, Image acquisition boards Stand-alone instruments and devices 4
Accessing Data from MATLAB Instrument Control Toolbox Serial devices, oscilloscopes, function generators, signal analyzers, etc. Data Acquisition Toolbox Data acquisition devices and PC sound cards Image Acquisition Toolbox Cameras and frame-grabbers MATLAB Interfaces for communicating with everything 5
Data Analysis and Visualization Access Explore & Discover Share Built-in engineering and 3D visualizations mathematical functions Interpolation, filtering, smoothing, Fourier analysis Extensive plotting capabilities 2D, 3D, and volume visualization Tools for creating custom plots 6
Expanding the Capabilities of MATLAB Access Explore & Discover Share MathWorks add-on tools for: Curve-fitting Math, statistics, and optimization Machine Learning and Deep Learning Image processing and computer vision Signal processing and communications Parallel computing Control system design and analysis and more Color-Based Image Segmentation 7
Sharing Results from MATLAB Access Explore & Discover Share Automatically generate reports Live Editor Publish MATLAB files Customize reports using MATLAB Report Generator Package as an app or a custom toolbox to share MATLAB programs with people that have MATLAB 8
MATLAB Application Deployment Access Explore & Discover Share Share MATLAB programs with people who do not have MATLAB Royalty-free distribution Encryption to protect your intellectual property Standalone Application MATLAB Compiler Excel Add-in Hadoop MATLAB C/C ++ MATLAB Compiler SDK Java.NET MATLAB Production Server Create both standalone applications and components for integration Deploy to desktop, web, and enterprise applications 9
External Interfaces Calling Libraries Written in Another Language From MATLAB Python C/C++ Fortran Java COM components and applications (Visual C#,.Net, VB.NET) Calling MATLAB from Another Language Java libraries Python libraries C/C++ or Fortran MEX-file functions C shared libraries.net libraries COM objects RESTful and WSDL web services https://www.mathworks.com/support/sysreq/supported-language-interfaces.html 10
MATLAB Central Community for MATLAB and Simulink users Ask and Answer MATLAB Answers Get and Share Code File Exchange Link Exchange Read and Learn Blogs MATLAB Examples Play Cody 11
How to Use MATLAB? - Technical Overview MATLAB User Interface Working with variables Working with scripts Working with functions 12
MATLAB User Interface 13
14
Variables in the Workspace 19 1990 NaN 1.87 3.63 2.65 4.59 3.16 1 2.05 2.82 1.16 1991 1.96 1.92 3.45 2.9 4.5 3.46 1.3 2.49 3.01 1.14 1992 1.89 1.73 3.56 3.27 4.53 3.58 1.5 2.65 3.06 1.13 1993 1.73 1.57 3.41 3.07 3.68 4.16 1.56 2.88 2.84 1.11 1994 1.84 1.45 3.59 3.52 3.7 4.36 1.48 2.87 2.99 1.11 1995 1.95 1.53 4.26 3.96 4 4.43 1.11 2.94 3.21 1.15 1996 2.12 1.61 4.41 3.94 4.39 3.64 1.25 3.18 3.34 1.23 1997 2.05 1.62 4 3.53 4.07 3.26 1.47 3.34 3.83 1.23 1998 1.63 1.38 3.87 3.34 3.84 2.82 1.49 3.04 4.06 1.06 1999 1.72 1.52 3.85 3.42 3.87 3.27 1.79 3.8 4.29 1.17 2000 1.94 1.86 3.8 3.45 3.77 3.65 2.01 4.18 4.58 1.51 2001 1.71 1.72 3.51 3.4 3.57 3.27 2.2 3.76 4.13 1.46 2002 1.76 1.69 3.62 3.67 3.74 3.15 2.24 3.84 4.16 1.36 2003 2.19 1.99 4.35 4.59 4.53 3.47 2.04 4.11 4.7 1.59 2004 2.72 2.37 4.99 5.24 5.29 3.93 2.03 4.51 5.56 1.88 2005 3.23 2.89 5.46 5.66 5.74 4.28 2.22 5.28 5.97 2.3 2006 3.54 3.26 5.88 6.03 6.1 4.47 2.31 5.92 6.36 2.59 2007 3.85 3.59 6.6 6.88 6.73 4.49 2.4 6.21 7.13 2.8 2008 4.45 4.08 7.51 7.75 7.63 5.74 2.45 5.83 7.42 3.27 11 numeric data double precision 15
The Variable Editor 16
Plotting the Data Automatic code Examples 17
Plotting Multiple Columns >> plot(year,prices) 8 7 6 5 4 Australia Canada France Germany Italy Japan Mexico South Korea UK USA 3 2 1 1990 1992 1994 1996 1998 2000 2002 2004 2006 2008 18
Plot Tools 19
20
How to Use MATLAB MATLAB User Interface Working with variables Working with scripts Working with functions 21
MATLAB Commands 22
Using Built-In Functions and Constants 23
Creating Vectors Arbitrary data >> x = [2,3,5,7,11,13]; Equally-spaced values n subdivision points a dx b x >> x = a:dx:b; >> x = linspace(a,b,n); 24
Creating Matrices >> A = [1,2,3; 4,5,6; 7,8,9]; or >> A = [1 2 3; 4 5 6; 7 8 9] data entry mode 1 4 7 2 5 8 3 6 9 25
Concatenation >> A A = 1, 2, 3 4, 5, 6 7, 8, 9 >> C = [A,B] C = 1 2 3 1 0 0 4 5 6 0 1 0 7 8 9 0 0 1 >> B B = 1, 0, 0 0, 1, 0 0, 0, 1 >> D = [A;B] D = 1 2 3 4 5 6 7 8 9 1 0 0 0 1 0 0 0 1 [] 26
Array Operations 27
Array Operations 28
Array Operations 29
Matrix Mathematics 30
Mathematical Operations Performed on all elements of a vector sin a b c sin( a) sin( b) sin( c) The operation is vectorized 1 2 3 4 sin 0.8415 0.9093 0.1411 0. 7568 sin sind sinh asin exp log log2 log10 sqrt nthroot abs angle floor ceil round mod 31
Mathematical Operations Performed on all elements of a matrix a sin c 1 3 b d sin( a) sin( c) The operation is vectorized 2 4 sin sin( b) sin( d) 0.8415 0.1411 0.9093 0. 7568 sin sind sinh asin exp log log2 log10 sqrt nthroot abs angle floor ceil round mod 32
Tables 34
Storing Data as a Table 36
How to Use MATLAB MATLAB User Interface Working with variables Working with scripts Working with functions 37
The MATLAB Editor edit 38
Script Files H1 line % CALLMODEL Models a blue whale B call. % % Uses a model of the form y = A.*y0 % where A = A0*exp(-B*t).*sin(2*pi*fm*t) % and y0 is a sum of harmonics % yn = sin(2*pi*n*f0*t) Help Code % Create the time base for the signal. fs = 4000; t = 0:(1/fs):1.5; % Set the fundamental frequency of the call. f0 = 175; Comments % Create the harmonics. y0 = sin(2*pi*f0*t) + sin(2*pi*2*f0*t) + sin(2*pi*3*f0*t); callmodel.m 39
Live Script SunriseSunset.mlx 40
How to Use MATLAB MATLAB User Interface Working with variables Working with scripts Flow Control and functions 41
Flow Control 42
Functions function [output_1, output_2] = function_name(input_1, input_2, input_3) 43
44
45
Examining Values 46
Test Your knowledge 48
49
50
51
MATLAB Onramp 52
TAH Campus License at a Glance Includes all faculty, researchers, and students Installation on campus-owned machines, as well as faculty-owned and studentowned personal computers https://www.systematics.co.il/products/mathworks/products/matlab-fortechnion Access at home and in the classroom, in lab and field research, and off-network provides the widest and up-to-date array of products, supporting everything from introductory level courses to advanced academic research MATLAB Grader automates and gamifies student programming assignments MATLAB Academic Online Training Suite is cost-effective training for all users MATLAB Online provides access from a web browser 53
MathWorks Product Overview Simulink Product Family Application-Specific Products Interface to hardwarehttps://www.mathworks.com/academia/hardware.html?s_tid=acport_hw_sp_til 54
Diverse Users https://www.mathworks.com/academia/student-competitions.html?s_tid=acport_sc_sp_til 55
Thank You! 60