Matlab review - PowerPoint PPT Presentation

1 / 19
About This Presentation
Title:

Matlab review

Description:

Matlab review. Matlab is a numerical ... if the file is an ascii table, use load - if the file is ascii but not a table, file i/o needs fopen and fclose ... – PowerPoint PPT presentation

Number of Views:41
Avg rating:3.0/5.0
Slides: 20
Provided by: tonyc7
Category:
Tags: ascii | matlab | review | table

less

Transcript and Presenter's Notes

Title: Matlab review


1
Matlab review Matlab is a numerical analysis
system Can write programs, but they arent
compiled Should still use structured
programming Should still use comments Comments
are indicated by at the beginning of the line
2
Matlabs basic component is a vector All
operations are optimized for vector use Loops run
slower in Matlab than in Fortran (not a vector
operation) Really good help command
3
  • Matlab topics and how it differs from Fortran
  • Syntax
  • Data types
  • Input-output
  • Mathematics
  • Do loops
  • If then structures

4
Syntax No complicated rules Perhaps the most
important thing to remember is semicolons at the
end of a line surpress output Type more on to
keep text from leaving screen too fast
5
Data types All numbers are double precision Text
is stored as arrays of characters. You dont have
to declare the type of data (defined when running)
6
Vectors Everything in Matlab is a vector (or
matrix) Even single value variables size command
gives size of a vector
7
Example pi ans 3.1416 size(pi) ans
1 1
a1 2 3 4 a 1 2 3 4
size(a) ans 2 2
Pi
a
8
Input-output Values can be assigned by typing
vector name value Matlab automatically prints
the results of any calculation (unless surpressed
by ) Use disp to print out text to screen
9
To read files in - if the file is an ascii table,
use load - if the file is ascii but not a table,
file i/o needs fopen and fclose Reading in data
from file using fopen depends on type of data
(binary or text).
10
Mathematics All the standard operators
,-,,/, Built-in functions too sin(), cos(),
exp(), etc. IMPORTANT These operators are
vectorized.
11
Example Vectorized operators
But ab gives an error because dimensions are
incorrect. Need to use .
12
Likewise
13
Do loops They do exist in Matlab, and sometimes
you need them for i1n for j1n a(i,j)1/(ij
-1) end end
14
Because of vectorization , can often do loops
more efficiently
for i13 bsin(i) end
i13 bsin(i) is much faster
15
If - then also exists The general form of the IF
statement is IF expression
statements ELSEIF expression
statements ELSE statements END
16
  • Possible comparisons are
  • equals
  • lt less than
  • gt greater than
  • lt less than or equal to
  • gt greater than or equal to
  • not equal to

17
Programming In Matlab, one can write a set of
commands in a text file (called an m-file, since
the ending must be .m) These commands can be a
program Type the name of the m-file in the Matlab
environment to run the program
18
Difference betweem scripts and functions Scripts
share variables with the main workspace Functions
do not
19
One of the best things about Matlab is
graphics plot is the one you will be using most
often many other 3 dimensional plotting functions
Write a Comment
User Comments (0)
About PowerShow.com