Академический Документы
Профессиональный Документы
Культура Документы
Introduction
2. The MATLAB environment
3. MATLAB Basics
4. Branching Statements
5. Loops
6. Plotting graphs
7.Advantages of MATLAB
8. Disadvantages of MATLAB
9. Conclusion
10. Bibliography
Introduction
MATLAB (short for MATrix LABoratory)
Arrays
Vectors
Matrices
1.Variables and Arrays
Initializing Variables in
Assignment Statements
An assignment statement has general form
var = expression
* var = 40i;
* var = var/5;
* array = [1 2 3 4];
* x = 1; y = 2;
* a = [0 1+7]; b = [a(2) 7 a];
There a = [0 8] & b = [8 7 0 8]
---- echoing------
If a semicolon is added at the end of
statement
echoing disappears.
>> x = 1 : 2 : 10
x=
1 3 5 7 9
Initializing with Built-In-
Function
1. Relational Operators:
The general form of relational operator is:
a1 op a2
Operator Operation
== equal to
~= not equal to
> Greater than
< less than
>= greater than equal
to
<= less than equal to
Logical Operator
Logical operators are operators with one or two
logical operands that yields a logical
results.There are 5 binary logical operators:
AND, inclusive OR, and exclusive OR, and one
unary operator: NOT.
The general form of logic binary operation is
l1 op l2
And the general form of unary logic operation is
Op l1
Where l1 & l2 are expressions & variables and
op is one of the logic operators
Branching Statements
and Program Design
The if Construct
The if construct has form:
If control_expr_1
Statement 1
Statement 2
....
else if control_expr_2
statement 1
statement 2
....
else
statement 1
statement 2
....
End
The switch construct
Switch ( switch_expr)
Case case_expr_1,
Statement 1
Statement 2
...
Case case_expr_2,
Statement 2
Otherwise,
Statement 2
End
The For Loop
for index = expr
statement 1
...
end
MATLAB input and output functions
Category Function
Description
Load/Save Workspace load Load
workspace.
Save Save
Workspace.
File Opening and Closing fopen Open
file.
Fclose Close file.
Binary I/O fread Read binary
data from file
Fwrite Write binary
data to file.
Formatted I/O fscan Read formatted
data from.
fprintf Write formatted
data to file.
fget l Read line from
file, discard new line character.
fget s Read line from
file, keep newline character.
File Positioning, Status, delete Delete file.
exist Check for
existence of a file.
ferror Inquire I/O error
status
feof Test for end of
file.
Plotting graphs
15
10
5
10
0 1 2 3 4 5 6 7 8 9 10
plot of y=x.210.*x+15
15
10
5
y
5
10
0 1 2 3 4 5 6 7 8 9 10
x
1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Logarithmic scales
Matlab has provided a way to convert the
normal graphical area in to a logarithmic
graphical area .
100
150
200
250
300
350
400
450
Platform independent
Predefined functions
MATLAB compiler
DISADVANTGES
CONCLUSION
MATLAB is so much powerful that it can handle any
of the
Technical computing.