Matlab ia a very important software in the engineering world
In our university studying and practicing matlab depends in the student himself
here is a brief totorial (clear steps) to help you in using matlab 7.0 version
Part 1: MATLAB background
MATLAB stands for
MATrix LABoratory, which is a powerful, high level language and a
technical computing environment that provides core mathematics and advanced graphical
tools for data analysis, visualization and algorithm development. MATLAB is intuitive
and easy to use since it follows many other programming languages like C. In MATLAB
every thing are matrices, matrix operations are programmed so that element-wise
operations or linear combinations are more efficient than loops over the array elements.
. How to start and quit?
Start: double click on the MATLAB icon on the desktop
[/B][LEFT]to exit, type quit at the command promp
. Working with MATLAB
Once a MATLAB session is started there are two ways to work with:
- Command window
a. For small tasks like execution of a single command.
[/B][LEFT]As a calculator for small calculations.
- M- files
a. Used for large programs and projects.[/LEFT]
b. For funqctions.
[LEFT]c. Known as m-file because of their .m extension.
. Writing Comments
Comments can be added to the m-file program or function to clarify the statements or
provide additional information, In MATLAB comments begin with the modulus
character % and they are colored in green automaticall.
. Getting help in MATLAB
MATLAB provides a very powerful and useful help and information on the commands
and how to use specific built-in functions.
a- Help function name: [/LEFT]
Displays a brief description and the syntax for the function.
[B]:('b- Helpwin (‘function name’
[/B][LEFT]the difference is that the previous command displays
the information on the command window while the second command opens a
separate window called the ‘help browser’.
[/B][LEFT]Helps in finding functions related to a particular topic, if you want to
know if MATLAB has a function for performing an operation but you don’t knowthe exact correct name of the function.. Matrix ManipulationMATLAB is case sensitive i.e. ‘a’ and ‘A’ will be treated as two different variables.The general structure of variables in MATLAB is a Matrix which is an m x n matrixwhere m represents the number of rows and n represents the number of columns, but ifthe variable has only one entry it will be a 1x1 matrix (Scalar), moreover if the matrix(has only one row or one column then it is called (Vector5.1 Creating matrix in MATLAB:: By explicitly entering the elements: note the following:- Name your matrix.- Separate the elements of a row with blank or commas.- Use a semicolon to indicate new column.- Surround the entire list of elements with square brackets.Examples:A = [1 2 3 4 5 6] % A is a row vectorX= [1 2 3 ; 4 5 6 ; 7 8 9 ] % X is a 3 by 3 matrixY = [0 ; 1 ; 3 ; 5] % Y is a column vectorB =  % B is a scalar( By generating sequence of numbers using colon operator
[LEFT]. Define the initial,
final and increment values (lower limit: increment: upper limit), note that the default
value for the increment (in case it was not provided) is one.
X = 1:10
Z = 0: 0.1: 20
[B] By using special built in functions
[/B][LEFT]: There are several useful built in function that
can be used to generate vectors and matrices such as ZEROS, ONES, EYE, and RAND
- Use the Help to explore the above functions.
- Generate a row vector of zeros of size 15.
- What is the index of the fist element in the matrix (0 or 1)? Think!
Functions also called m-files are widely used and make life easier while using MATLAB.
M-files group several commands that are stored in a text file with the extension .m and
can be used later as any normal built in function.
Write a MATLAB function RANDINT that generates random integral matrix.
RANDINT returns an m-by-n matrix with entries between 0 and 9.
a = randint(m,n) n
%RANDINT Randomly generated integral matrix.
% randint(m,n) returns an m-by-n such matrix with entries
% between 0 and 9.
a = floor(10*rand(m,n)) n
Important notes and comments
[/B]is the output of the function.
m,n) are the inputs of the function).- Store the file containing the function definition in the work directory.
- randint is the name of the function.
- The function should be saved as a file with the same name of the function name.
I hope you get benifit from this introduction
Ramadan kareem &