0% found this document useful (0 votes)
11 views

MATLAB_MODULE_1_updated.pptx

MATLAB is a high-performance programming platform designed for engineers and scientists to perform numerical computations, data analysis, and visualization. It features a matrix-based language and provides built-in functions for various scientific computations, including signal processing and optimization. The course aims to teach students the syntax, functions, and capabilities of MATLAB, enabling them to develop algorithms and create visualizations.

Uploaded by

rahulnayanarahul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

MATLAB_MODULE_1_updated.pptx

MATLAB is a high-performance programming platform designed for engineers and scientists to perform numerical computations, data analysis, and visualization. It features a matrix-based language and provides built-in functions for various scientific computations, including signal processing and optimization. The course aims to teach students the syntax, functions, and capabilities of MATLAB, enabling them to develop algorithms and create visualizations.

Uploaded by

rahulnayanarahul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 58

Matlab Programming

By
Sunita Shirahatti
Assistant Professor, Dept. ECE, JSSATEB
What is MATLAB?
• MATLAB® is a programming platform designed specifically for
engineers and scientists to analyze and design systems and
products that transform our world.

• The heart of MATLAB is the MATLAB language, a matrix-based


language allowing the most natural expression of computational
mathematics.
MATLAB
• MATLAB is a program for doing numerical computation.
• It was originally designed for solving linear algebra type problems using
matrices. It’s name is derived from
MATrix LABoratory

• MATLAB has since been expanded and now has built-in functions for solving
problems requiring data analysis, signal processing, optimization, and several
other types of scientific computations.
• It also contains functions for 2-D and 3-D graphics and animation.
What is the importance of MATLAB?
• Data Analysis and Visualization: MATLAB provides powerful
tools for data analysis, manipulation, and visualization.

• It offers functions for data cleaning, filtering, statistics, plotting,


and creating interactive visualizations.

• Algorithm Development: MATLAB is widely used for developing


and implementing algorithms.
Course Outcomes
When was MATLAB first introduced?
• December 1984
• PC-MATLAB made its debut in December 1984 at the IEEE
Conference on Decision and Control in Las Vegas.
Pro-MATLAB, for Unix workstations, followed a year later.

MATLAB logo
What is MATLAB and its types?
• MATLAB allows
- matrix manipulations
- plotting of functions and data
- implementation of algorithms
- creation of user interfaces
-interfacing with programs written in other languages.

• MATLAB is a high-level programming language designed for


engineers and scientists that expresses matrix and array
mathematics directly.
What are the main features of MATLAB?
Why MATLAB is used for simulation?
• MATLAB®, Simulink®,
Stateflow®, and Simscape™
are tools for designing
systems, simulating their
behavior in an environment,
and automatically generating
code that can be deployed to
hardware.
What is Simulink used for?

• Simulink is the platform for Model-Based Design that supports


system-level design, simulation, automatic code generation, and
continuous test and verification of embedded systems.

• Key capabilities include: A graphical editor for modeling all


components of a system.
Is MATLAB a language or IDE?
• Like other well-known programming languages like Java, C#,
etc., MATLAB has its own Integrated Development Environment
(IDE) and collection of libraries.

• Since it was initially known as the matrix programming language,


MATLAB is an acronym for "Matrix Laboratory."

• It is a programming language of the fourth generation.

• MATLAB includes a programming language, interactive apps, highly


specialized libraries for engineering applications, and tools for
automatically generating embedded code.
• What is biggest advantage of MATLAB?
• MATLAB is built to handle mathematical operations like matrix
multiplication and addition easily, which means you can do it using
a single code.
• Standard loops that can be written in C or C++ can be
conveniently written in MATLAB using the same length of code or
even shorter.

• Is MATLAB a useful skill?


• It is an essential tool for engineers, data analysts, scientists, and
researchers who work with large amounts of data.

• Is MATLAB free to use?


• Basic version of MATLAB Online: A basic version of MATLAB
Online provides 20 hours per month of free use and access to 10
commonly used toolboxes.
Is MATLAB open source?
• But MATLAB is a proprietary tool. Without access to its source
code, you have limited understanding of how it works and how
you can modify it.

• It is also prohibitively expensive for many people outside of an


academic setting, where license fees for a single copy can
reach into the thousands of dollars.
Course outcome

At the end of the course the student will be able to:

1. utilize the syntax of MATLAB for arithmetic computations, arrays, matrices.

2. Utilize the built-in function, saving and loading data, and create plots

3. develop program using symbolic computations, Importing and exporting data and files

4. develop program using character strings, Command line functions and Built-in functions.
Module -1
• Introduction
• Basics of MATLAB
• Simple arithmetic calculations
• creating and working with arrays and numbers.
What is MATLAB?
• MATLABTM is a software package for high-performance numerical
computation and visualization.
• It provides an interactive environment with hundreds of built-in
functions for technical computation, graphics, and animation.
• It also provides easy extensibility with its own high-level programming
language
Features and capabilities of MATLAB
• MATLAB’s built-in functions provide excellent tools for linear algebra
computations, data analysis, signal processing, optimization, numerical
solution of ordinary differential equations (ODEs), quadrature, and many
other types of scientific computations.

• There are also several optional ‘Toolboxes’ available from the developers
of MATLAB.

• Toolboxes are collections of functions written for special applications


such as Symbolic Computation, Image Processing, Statistics, Control
System Design, Neural Networks, etc.
• The basic building block of MATLAB is the matrix.

• The fundamental data-type is the array.

• Vectors, scalars, real matrices and complex matrices are all


automatically handled as special cases of the basic data-type.

• MATLAB supports almost every computational platform.


Examples carried out in MATLAB is as
shown in Fig 2.
MATLAB Windows: The three basic
windows is as shown in Fig. 3
Basics of MATLAB - MATLAB window
1. Command window:
• This is the main window.
• It is characterized by the MATLAB command prompt ‘ >>’.
• When you launch the application program, MATLAB puts you in this
window.
• All commands, including those for running user-written programs, are
typed in this window at the MATLAB prompt.

Current Directory:

• This is where all your files from the current directory are listed. You
can do file navigation
Launch Pad:
This subwindow lists all MATLAB related applications and toolboxes that
are installed on your machine.
You can launch any of the listed applications by double clicking on them.

Workspace:
This subwindow lists all variables that you have generated so far and
shows their type and size.
You can do various things with these variables, such as plotting, by
clicking on a variable and then using

Command History:
All commands typed on the MATLAB prompt in the command window
get recorded, even across multiple sessions.
2. Graphics window:
The output of all graphics commands typed in the command window are
flushed to the graphics or Figure window, a separate gray window with
(default) white background color.
The user can create as many figure windows as the system memory will
allow.

3. Edit window:
This is where you write, edit, create, and save your own programs in files
called ‘M-files’. Y
you can use any text editor to carry out these tasks.
MATLAB provides its own built-in editor.
On-line help : On-line documentation: MATLAB provides on-line help
for all its built-in functions and programming language constructs.
The commands lookfor, help, helpwin, and helpdesk provide on-line
help.

Demo: MATLAB has a demonstration program that shows many of its


features. The program includes a tutorial introduction that is worth
trying.

Type demo at the MATLAB prompt to invoke the demonstration


program, and follow the instructions on the screen
•Data-type: The fundamental data-type in MATLAB is the array. Also it covers data objects like integers, doubles (real
numbers), matrices, character strings, structures and cells.

•Dimensioning: Here, dimension statements are not required for vectors or arrays. Instead the commands are size and
length are used to know the dimension of a vector.

•Case sensitivity: Eg: a and A are different

•Output Display: **(Using of ;)


❖Paged output: To show one screen of output at a time, type more on
❖Output format: **
1. format short 31.4159
2. format short e 3.1416e+001 ------------------- 5 digit and floating point
3. format long 31.41592653589793
4. format long e 3.141592653589793e+001 --------- 5 digits for single precision 15 digits for double precision
5. format short g 31.416 -----------------------5 digits including numbers before and after decimal point
6. format long g 31.4159265358979 ------------------7 digits for single precision 15 digits for double precision
7. format hex 403f6a7a2955385e ---------------- Hexadecimal number representation
8. format rat 3550/113 ----------- Rational Format
9. format bank 31.42 ---------------- Bank transaction format

•Command history: Up-arrow key


MATLAB File types

Five different types in MATLAB are:


1. M-files:
• These are std. ASCII text files, with .m extension to the filename
• Two types of these files are: script files and function files

2. Mat-files:
• These are binary data-files created by MATLAB when we save data with the save command.
• The data is written in a special format where MATLAB only can read it
• These files can be loaded into MATLAB with the load command

3. Fig-files:
• These are binary figure files with a .fig extension

4. P-files
• These are compiled M-files with a .p extension that can be executed in MATLAB directly. **

5. Mex-files
• These are MATLAB-callable Fortran and C programs with a .mex extension to the filename
General commands you should remember
session 1: A Minimum MATLAB Session
• Goal: To learn how to log on, invoke MATLAB, do a few trivial calculations, quit MATLAB, and
log off

• What you are going to learn:


• • How to do simple arithmetic calculations.
The arithmetic operators are:
+ addition,
− subtraction,
∗ multiplication,
/ division,
ˆ exponentiation.
• How to assign values to variables.
• How to suppress screen output.
• How to control the appearance of floating point numbers on the screen.
• How to quit MATLAB.
• The MATLAB commands/operators used are
+, -, *, /, ^, ;
sin, cos, log, format ,quit
Exercise problems
Arrays
What you are going to learn:
• How to create row and column vectors.
• Howto create a vector of n numbers linearly (equally) spaced between
two given numbers a and b.
• How to do simple arithmetic operations on vectors.
• How to do array operations:
.* term by term multiplication,
./ term by term division, and
.^ term by term exponentiation.
• How to use trigonometric functions with array arguments.
• How to use elementary math functions such as square root, exponentials,
and logarithms, with array arguments.
EXCERCISES
Lesson 3: Creating and Printing Simple Plots

What you are going to learn: >>


• How to generate x and y coordinates of 100 equidistant points on a
unit circle.
• How to plot x vs y and thus create the circle.
• How to set the scale of the x and y axes to be the same, so that the
circle looks like a circle and not an ellipse.
• How to label the axes with text strings.
• How to title the graph with a text string.
• How to get a hardcopy of the graph.
MATLAB commands used

• plot 🡪 creates a 2-D line plot


• axis 🡪 changes the aspect ratio of x and y axes
• xlabel 🡪 annotates the x-axis
• ylabel 🡪 annotates the y-axis
• title 🡪 puts a title on the plot
• print 🡪 prints a hardcopy of the plot.
Example
• Lets draw a circle of unit radius.
• To do this, first generate the data (x- and y-coordinates of, say, 100
points on the circle), then plot the data, and finally print the graph.
• For generating data, use the parametric equation of a unit circle:
x = c os θ, y = sin θ, 0 ≤ θ ≤ 2π.
Creating and executing script file
✔ A Script File is a user-created file with a sequence of MATLAB
commands in it.
✔ The file must be saved with a ‘.m’ extension to its name,
thereby,
making it an M-file.
✔ A script file is executed by typing its name (without the ‘.m’
extension’) at the command prompt.
Steps:
1. Create a new file:
Select New M-File from the File menu. A new
edit window should appear.
2. Type the following lines into this file. Lines starting
with a % sign are interpreted as comment
lines by MATLAB and are ignored.
3. Write and save the file under the name circle.m
4. Now get back to MATLAB and type the following commands
in the command window to execute the script file.
Script File example
EXERCISES
Creating and Executing a Function File
Steps
1. Open the new script file
2. Edit the file like below
3. save the file as circlefn.m
4. We can execute the function circlefn in three different ways.
Example - 1
Convert temperature: Write a function that outputs a conversion-table for Celsius and
Fahrenheit temperatures. The input of the function should be two numbers: Ti and Tf,
specifying the lower and upper range of the table in Celsius. The output should be a two
column matrix: the first column showing the temperature in Celsius from Ti to Tf in the
increments of 1oC and the second column showing the corresponding temperatures in
Fahrenheit.
Example - 2
• Write a function factorial to compute the factorial n! for any integer n.
The input should be the number n and the output should be n!.
Example - 3

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy