Class 2 Sheet 1
Class 2 Sheet 1
Class 2 Sheet 1
2nd Class
University of Ninevah
SIGNALS AND SYSTEMS LABORATORY
Collage :Electronics Engineering
By: Abdulbasit Sabaawi
Dept: Computer and Information
Experiment [1]
Introduction to MATLAB
Introduction:
In this introduction we will describe how MATLAB handles simple numerical
expressions and mathematical formulas. MATLAB is a high-performance language for
technical computing. It integrates computation, visualization, and programming
environment. Furthermore, MATLAB is a modern programming language environment:
it has sophisticated data structures, contains built-in editing and debugging tools, and
supports object-oriented programming. These factors make MATLAB an excellent tool
for teaching and research. MATLAB has many advantages compared to conventional
computer languages (examples: C and FORTRAN) for solving technical problems.
MATLAB is an interactive system whose basic data element is an array that does not
require dimensioning. The software package has been commercially available since 1984
and is now considered as a standard tool at most universities and industries worldwide.
The name MATLAB stands for matrix laboratory. It has evolved over a period of years
with input from many users. In university environments, it is the standard instructional
tool for introductory and advanced courses in mathematics, engineering, and science. In
industry, MATLAB is the tool of choice for high-productivity research, development,
and analysis. MATLAB features a family of add-on application-specific solutions called
toolboxes. There are toolboxes for signal processing, control systems, symbolic
computations, simulation, optimization and many other fields of applied science and
engineering.
Starting and quitting MATLAB
You can enter MATLAB by double-clicking on the MATLAB shortcut icon on the
desktop. This will open the MATLAB window which contains the following other
windows:
1- The command window
2- The command history
3- The current directory
4- The workspace
5- The help browser
6- The start bottom
1
SIGNAL AND SYSTEMS LABORATORY
To end your MATLAB session, select File -> Exit MATLAB in the main menu, or type
quit in the Command Window.
1- Command Window
Use the Command Window to enter variables and to run functions and M-file scripts.
Press the up arrow key to recall a statement you previously typed. Edit the statement as
needed and then press Enter to run it.
2- Command History
Statements you enter in the Command Window are logged in the Command History.
From the Command History, you can view previously run statements, as well as copy and
execute selected statements. You can also create an M-file from selected statements.
3- Current Directory
A quick way to view or change the current directory is by using the current directory
field in the desktop toolbar. To search for, view, open, and make changes to MATLAB
related directories and files, use the MATLAB Current Directory browser. Alternatively,
you can use the functions dir, cd, and delete.
4- Workspace Browser and Array Editor
Any variable that is defined in the command window or in an M-file after execution is
added to the workspace.
2
SIGNAL AND SYSTEMS LABORATORY
5- Help Browser
Use the Help browser to search for and view documentation and demos for all your
math works products. The help browser is an HTML viewer integrated into the
MATLAB desktop. You have different ways to look for something in the MATLAB
help:
1- Click on the (help) in MATLAB window.
2- Press F1.
3- Type (help) in the command window.
4- From an m-file, select an instruction, right click on it and then select (help on
selection).
help
The most important function for learning MATLAB on your own
•To get info on how to use a function:
»help sin
Help lists related functions at the bottom and links to the doc.
•To get a nicer version of help with examples and easy-to-read descriptions:
»doc sin
•To search for a function by specifying keywords:
»doc + Search tab
>>x= 1+2*3
x=
7
Now x is a known variable and can be used in other expressions, for example, we can
compute (4x) as follows:
>> 4*x
ans=
28.0000
4
SIGNAL AND SYSTEMS LABORATORY
If we have two expressions, each of them has the same numbers and mathematical
operations, but one of them contains parenthesis as follows:
>>(1+2)*3
ans =
9
>> 1+2*3
ans =
7
By adding parentheses, these two expressions give different results: 9 and 7.The order
in which MATLAB performs arithmetic operations is exactly as that taught in high
school algebra courses. Exponentiations are done first, followed by multiplications and
divisions, and finally by additions and subtractions. However, this order can be changed
by inserting parentheses. For example, the result of 1+2*3 is quite different than the same
expression with parentheses (1+2) *3 . Parentheses can always be used to overrule
priority, and their use is recommended in some complex expressions to avoid ambiguity.