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

MATLAB

The document describes the different windows in MATLAB and their purposes. The main windows are the Command Window, Figure Window, Editor Window, Help Window, Launch Pad Window, Command History Window, Workspace Window, and Current Directory Window. The Command Window is used to enter variables and run programs. The Figure Window displays graphic outputs. The Editor Window is used to create and debug script and function files. The Help Window provides help information.
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

MATLAB

The document describes the different windows in MATLAB and their purposes. The main windows are the Command Window, Figure Window, Editor Window, Help Window, Launch Pad Window, Command History Window, Workspace Window, and Current Directory Window. The Command Window is used to enter variables and run programs. The Figure Window displays graphic outputs. The Editor Window is used to create and debug script and function files. The Help Window provides help information.
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 18

MATLAB Windows

Window Purpose

Command Window Main Window, enters variables, runs


programs
Figure Window Contains output from graphic commands

Editor Window Creates and debugs SCRIPTS and


FUNCTION files
Help Window Provides help information

Launch Pad Window Provides access to tools, demos and


documentation
Command History Window Logs commands entered in the
Command Window
Workspace Window Provides info about the variables that are
used
Current Directory Window Shows the files in the current directory 1
Working in the Command
Window
 Type a command by placing cursor next to the command
prompt (>>)
 Typed command is executed by pressing the Enter key. The
last command is executed
 It is not possible to go back to a previous line in the Command
Window, make a correction and then re-execute the command
 If a command is too long to fit in one line, it can be continued
to the next line by typing three dots … (called an ellipsis) and
pressing the Enter key
 Continuation of the line is then typed in the next line
 Commands can continue line after line up to a total of 4096
characters,
2
The semicolon (; ):

• When a command is typed in the Command Window and


the Enter key is pressed, the command is executed.
• Any output that the command generates is displayed in the
Command Window.
• If a semicolon (; ) is typed at the end of a command the
output of the command is not displayed.
• Typing a semicolon is useful when the result is obvious or
known, or when the output is very large.
• If several commands are typed in the same line, the output
from any of the commands will not be displayed if a
semicolon is typed between the commands instead of a
comma.
3
Typing %
• When the symbol % (percent symbol) is typed in the
beginning of a line, the line is designated as a comment.
• This means that when the Enter key is pressed the line is
not executed.
• The % character followed by text (comment) can also be
typed after a command (in the same line).
• This has no effect on the execution of the command.
• Usually there is no need for comments in the Command
Window.
• Comments, however, are frequently used in programs to
add descriptions, or to explain the program

4
Creating Arrays
• An array is a list of numbers arranged in rows and /or columns
• The simplest array, (one-dimensional) is a row or a column of
numbers
• A more complex array (two-dimensional) is a collection of
numbers arranged in rows and columns
• One use of arrays is to store information and data, as in a table
• In science and engineering, one-dimensional arrays frequently
represent vectors and 2-D arrays often represent matrices
• In addition to arrays that are made of numbers, arrays in
MATLAB can also be made of a list of characters, which are
called strings

5
• A 1-D array is a list of numbers that
is placed in a row or a column
• One example is the representation of
the position of a point in space in a
3-D Cartesian coordinate system
• The position of point A is defined
by a list of 3 numbers 2, 4, and 5,
which are coordinates of the point where i, j, k are
• The position of point A can be unit vectors in the
expressed in terms of a position direction of the x,
y, and z axis
vector:
rA= 2i + 4j + 5k respectively
Creating a vector from a known list of
numbers
Year 1984 1986 1988 1990 1992 1994 1996
Population 127 130 136 145 158 178 211
(Millions)

• A vector is created by assigning the elements of the vector to a


variable.
• The vector is created by typing the elements (numbers) inside
the square brackets []
Variable_name = [ type vector elements]
• To create a row vector type the elements with a space or a
comma between the elements inside square brackets
• Create a column vector by typing the left bracket [ and then
enter the elements with a semicolon between them, or press the
Enter key after each element
• Type the right square bracket ] after the last element 7
Creating a vector with constant spacing by
specifying the first term, the spacing, and the last
term
• In a vector with constant spacing the difference between the elements is the same

For example, in the vector

V = 2 4 6 8 10
The spacing between the elements is 2
• A vector in which the first term is m, the spacing is q, and the last term is n is created
by typing
Variable_name = [m : q : n] or
Variable_name = m : q : n (brackets are optional)
• Consider these
x = [1 : 2 : 13]
y = [1.5 : 0.1 : 2.1] or
z = [-3 : 7] if spacing is omitted, the default is 1
xa = [21 : - 3 : 6]
• If the numbers m, q, n are such that the value of n cannot be obtained by adding q’s
to m, then ( for positive n) the last element in the vector will be the last number that
8
does not exceed n
Creating a vector with constant spacing by
specifying the first and last terms, and the number
of terms
• A vector in which the first element is xi, the last element is xf, and the
number of elements is n is created by typing the linspace command
(MATLAB determines the correct spacing)

Variable_name = linspace (xi , xf , n)

• Examples are
va = linspace (0,8,6)
vb = linspace (30,10,11)
u = linspace (49.5, 0.5) (when the number of elements
is omitted, the default is 100)
CREATING A Two-DIMENSIONAL
ARRAY (MATRIX)
• A two-dimensional array, also called a matrix, has numbers in rows
and columns.
• Matrices can be used to store information like in a table.
• Matrices play an important role in linear algebra and are used in
science and engineering-to describe many physical quantities.
• A m x n matrix has m rows and n columns, and m by n is called the
size of the matrix.

• variable_name = [ 1st row element; 2nd row elements; 3rd row


elements; ..... ; last row elements]
CREATING A Two-DIMENSIONAL ARRAY
(MATRIX)

• Rows of a matrix can also be entered as vectors using the


notation for creating vectors with constant spacing, or the
linspace command.
• For example:
>>A = [1:2:11;0:5:25; linspace (10,60,6); 67 2 43 68 4
13]
• In this example the first two rows were entered as vectors
using the notation of constant spacing
• the third row was entered using the linspace command, and
in the last row the elements were entered individually.
12
14
16
17
18

You might also like