MATLAB
• Matrix Laboratory
•Programming language developed by MathWorks
• used by engineers and scientists for performing engineering and scientific
calculations and data analysis.
• It can be run both under interactive sessions and as a batch job.
• It has numerous built-in commands and math functions that help in mathematical
calculations, generating plots, and performing numerical methods.
• It allows matrix manipulations; plotting of functions and data; implementation of
algorithms; creation of user interfaces; interfacing with programs written in other
languages, including C, C++, Java, and FORTRAN; analyze data; develop
algorithms; and create models and applications.
3.
Uses of MATLAB
•MATLAB is widely used as a computational tool in science physics, chemistry,
math and all engineering streams.
• It is used in a range of applications including −
• Signal Processing and Communications
• Image and Video Processing
• Control Systems
• Test and Measurement
• Computational Finance
• Computational Biology
4.
Important Features ofMatlab
▪ 1. Mathematical Computation
• Support basic math problems to complex ones.
• basic math operations like addition, subtraction, multiplication and division.
• Operations on scalar values, vectors, matrices, and multi-dimensional arrays
• all types of operation on matrices For example addition, multiplication ,
determinant, rank of matrix , inverse, adjoint, invertible matrix etc.
• computation like trigonometry, exponential, logarithmic, complex numbers,
statistics, probability , interpolation, differentiation, integration etc.
5.
Important Features ofMatlab
• 2. Plotting Data in Matlab
• Matlab comes with various functions to plot data.
• For plotting you can make use of functions like plot(), scatter(), bar(),
histogram(), pie(), boxplot() etc.
The data representation can be in the form of csv, text files or excel. Matlab
allows to import the data from these files and use them in the methods matlab
has
• save the plot as an image using the saveas() function.
6.
Important Features ofMatlab
• 3. Live Editor in Matlab
• feature that combines code, output, and formatted text in a single
interactive environment to write and execute Matlab code, visualize results,
and document all in one place.
• can also incorporate mathematical equations using LaTeX syntax, making it
easy to express mathematical concepts and formulas.
• Additionally, the Live Editor supports the insertion of images, hyperlinks,
and tables,
• can also export the Live Editor contents to various formats, such as PDF,
HTML, and Microsoft Word, making it convenient for sharing and
publishing your work.
7.
Important Features ofMatlab
• Programming and Scripting
• Matlab scripts, written in files with a .m extension, allow users to automate tasks by executing a
sequence of commands.
• These scripts can be run from the Matlab command window or integrated into larger projects.
• Matlab also supports the creation of reusable functions, which accept inputs and produce outputs,
enhancing code modularity and reusability.
• Matlab has vast collection of toolboxes, which provide specialized functions and algorithms for
diverse domains such as signal processing, image processing, optimization, machine learning, and
control systems.
• These toolboxes expand Matlab's capabilities and make it a versatile tool for various scientific and
engineering applications.
8.
Simulink
• Simulink isa graphical programming environment and simulation tool developed by MathWorks. It is widely
used in various engineering disciplines for modeling, simulating, and analyzing dynamic systems.
• Important features of Simulink
• The Simulink Block Diagram interface is very popular and a very important feature in Simulink. It helps
users to create system models using the blocks that represent different components and their relationships.
This approach helps in simplification of system designs and promotes a real based representation.
• Simulink multi domain modeling allows to integrate different disciplines such as electrical, mechanical and
control systems into a unified model. This capability enables the simulation of complex systems that involve
multiple domains.
• Simulink provides a vast library of pre-built blocks that represent various mathematical functions, physical
components, controllers, and more. These blocks can be customized, combined, and interconnected to create
complex system models efficiently.
• Simulink seamlessly integrates with MATLAB, allowing users to combine the power of Simulink's block
diagram modeling with MATLAB's extensive mathematical and data analysis capabilities. This integration
enables the use of MATLAB functions and scripts within Simulink models.
• Simulink provides tools for model verification and validation, enabling users to ensure the correctness and
reliability of their system models. It offers features like model checking, test generation, and formal methods
integration to enhance the quality of the models.
9.
Matlab Online
• Aweb-based version of Matlab, allows users to access and utilize Matlab's
features through a web browser.
• It also gives you Simulink access.
• This cloud-based platform offers convenience and flexibility for users who may
not have access to the desktop version.
• Since the software works in browsers, users don’t have to install software and
directly use the link after a few registration steps. It offers a free trial version for a
period of 30 days.
• https://matlab.mathworks.com/
10.
Understanding the MATLABEnvironment
• MATLAB development IDE can be
launched from the icon created on the
desktop.
• The main working window in
MATLAB is called the desktop.
• When MATLAB is started, the
desktop appears in its default layout −
Panels on thedesktop
• Current Folder − This panel allows you to access the project folders and files.
• Command Window − This is the main area where commands can be entered
at the command line. It is indicated by the command prompt (>>).
•
13.
Panels on thedesktop
• Workspace − The workspace shows all the variables created
and/or imported from files.
• Command History − This panel shows or return commands that
are entered at the command line.
14.
MATLAB editor
• Editorhelps to write code and to compile, debug and see the output.
• To open an editor, type edit or type edit along with filename (.m extension) in command window.
15.
Naming Variables
MATLAB iscase-sensitive !!!!!!!!!!
• Variable names consist of a letter followed by any number of
letters, digits or underscore.
Saving Your Work
• The save command is used for saving all the variables in the
workspace, as a file with .mat extension, in the current directory.
16.
Saving Workspace
• Workspace,is a place where you will find all the variables along with its most recent
values stored in memory. All the variables available in workspace are the ones which you
have used while writing your code or have imported data from other programs or files.
• The workspace acts as a temporary storage and allows you to create, read, update or
delete the variables.
• The workspace reference for the stored variables are available only if this matlab is open,
once close….. the workspace is erased.
• if you want to use it in future you can always save it with .mat extension.
17.
Clearing Workspace
• clc//clear command window
• clear // removes all the variables present in the workspace
• clear A // will only remove the variable A from the workspace
• Clearvars A B C // will remove variables A, B, C from the workspace
• By default when the matlab session is closed the workspace
is cleared.
Practice
5 + 5
Andpress ENTER
When you click the Execute button, or type Ctrl+E, MATLAB executes it immediately and the result returned is −
ans = 10
3 ^ 2 ( 3 raised to the power of 2)
ans = 9
sin(pi /2) % sine of angle 90o
ans = 1
7/0 ( Divide by zero)
ans = Inf warning: division by zero
732 * 20.3
ans = 1.4860e+04
MATLAB provides some special expressions for some mathematical symbols, like pi for π, Inf for ∞, i (and j)
21.
Use of Semicolon(;) in MATLAB
Semicolon (;) indicates end of statement.
However, if you want to suppress and hide the MATLAB output for an expression,
add a semicolon after the expression.
For example,
Live Dem
x = 3; y = x + 5
Execute , result returned is −
y = 8
Adding Comments
The percent symbol (%) is used for indicating a comment line. For example,
x = 9 % assign the value 9 to x
You can also write a block of comments using the block comment operators % { and % }.
The MATLAB editor includes tools and context menu items to help you add, remove, or change the format
of comments.
22.
x = sqrt(16)% defining x and initializing it with an expression
MATLAB will execute the above statement and return the following result −
x = 4
Multiple Assignments
multiple assignments on the same line
a = 2; b = 7; c = a * b
execute
c = 14
Workspace: Variable information
•who
• displays the names of the variables in workspace.
• Whos
• Variables currently in memory
• Type of each variables
• Memory allocated to each variable
• Whether they are complex variables or not
• Displays Size (1x 5) , Byte (40) , Class (double), Attribute
• The Bytes tells about the memory used by each variable.
• disp(A)
• display variable values