Вы находитесь на странице: 1из 3

1

1. Predefined Variables:
MATLAB includes a number of predefined variables. Some of the predefined variables use in
MATLAB programs is summarized in Table below:
Predefined Variables
Ans
Represents a value computed by an expression but not stored in variable
name.
Pi
Represents the number .
inf
Represents infinity which for instance occurs as a result of a division by zero.
A warning message will be displayed or the value will be printed as .
i
Defined as 1, which is: 0 + 1.0000i
J
Same as i.
NaN
Stands for Not a Number.
clock
Represents the current time in a six-element row vector containing year,
month, day, hour, minute, and seconds.
Date
Represents the current date in a character string format.
Workspace information
clear
Removes all variables from the memory.
clear x, y, z Clears/removes only variables x, y and z from the memory.
clear all
Clears all variables and functions from workspace.
Who
Lists the variables currently in the workspace.
Whos
Displays a list of the variables currently in the memory and their size together
with information about their bytes and class.
mlock fun
Locks function fun so that clear cannot remove it.
Clc
Clears command window, command history is lost.
home
Same as clc
Clf
Clears figure window.
On-line help
help
Lists topics on which help is available.
Helpwin
Opens the interactive help window.
help topic
Provides help on topic.
lookfor string
Lists help topics containing string.
Quit
Quits MATLAB
Exit
Same as quit.

1 of 3 Computer application 2

1st December 2015

Eng. Mazen khaled

2. Matrix fundamental:
When we enter a matrix we use this expression:
2 1 3
Assume that
A=[
]
4 2 10
The MATLAB input command is
>> A=[2,-1,3;4,2,10]; or A = [2 -1 3;4 2 10];
Similarly, for complex number elements of a matrix B

The MATLAB input command is


>>x=2;y=pi;
>>B = [5*x log(2*x)+7*sin(3*y); 3i 513i];
3. Built-in Functions:
Some of the built-in functions available in MATLAB for managing and handling arrays as
listed in Table below.
Function
Description
Example
Length(A)
Returns the number of elements >> A= [5 9 2 4];length(A);
in the vector A.
ans = 4
size(A)
Returns a row vector [m, n], >>A=[2 3 0 8 11 ;6 17 5 7 1];
where and m and n are the size >> size(A)
m n of the array A.
ans = 2 5
reshape(A, m, n)
Rearrange a matrix A that has r >> A= [3 1 4 ; 9 0 7];
rows and s columns to have m >> B = reshape(A, 3, 2)
rows and n columns with same
B=
dimension.
3 0
9 4
1 7
diag(v)
When v is a vector, creates a >> v = [3 2 1];
square matrix with the elements >> A= diag(v)
of v in the diagonal.
A=
3 0 0
0 2 0
0 0 1
diag(A)
When A is a matrix, creates a >> A= [1 8 3 ; 4 2 6 ; 7 8 3];
vector from the diagonal e = diag(A)
elements of A.
e=
1
2
3
2 of 3 Computer application 2

1st December 2015

Eng. Mazen khaled

4. Built-in Functions for Arrays:


Function
Description
mean(A)
If A is a vector, returns the mean
value of the elements
C = max(A)

[d,n]=max(A)

min(A)
[d,n]=min(A)
sum(A)

sort(A)

median(A)

det(A)

dot(a, b)

inv(A)

Example
>> A = [3 7 2 16];
>> mean(A)
ans = 7
>> A= [3 7 2 16 9 5 18 13 0 4];
>> C = max(A)
C=
18
>> [d ,n] = max(A)
d = 18
n=7

If A is a vector, C is the largest


element in A. If A is a matrix, C is
a row vector containing the largest
element of each column of A.
If A is a vector, d is the largest
element in A, n is the position of
the element (the first if several
have the max value).
The same as max(A), but for the >> A= [3 7 2 16]; min(A)
smallest element.
ans = 2
The same as [d, n] = max(A), but for the smallest element.
If A is a vector, returns the sum of >> A= [3 7 2 16];
the elements of the vector.
>> sum(A)
ans = 28
If A is a vector, arranges the >> A= [3 7 2 16];
elements of the vector in ascending >> sort(A)
order.
ans = 2 3 7 16
If A is a vector, returns the median >> A= [3 7 2 16];
value of the elements of the vector. >> median(A)
ans = 5
Returns the determinant of a >> A= [1 2 ; 3 4];
square matrix A.
>> det(A)
ans = 2
Calculates the scalar (dot) product >> a= [5 6 7];
of two vectors a and b. The vector >> b= [4 3 2];
can each be row or column vectors. >> dot(a,b)
ans = 52
Returns the inverse of a square >> A= [1 2 3; 4 6 8; a 1 2 3];
matrix A.
>> inv(A)
ans =
0.50 0.00 0.50
5.00 1.50 3.50
1.00 1.00 0.50

3 of 3 Computer application 2

1st December 2015

Eng. Mazen khaled

Вам также может понравиться