3
An Introduction to MATLAB
Purpose of the Handout
This handout was developed to help you understand the basic features of MATLAB and
also to help you understand the use of some basic functions. This is not a comprehensive
tutorial for MATLAB. To learn more about a certain function, you should use the online
help. For example, if you want to know more about the function ‘solve’, then type the
following command in the command window at the prompt:
help solve
Introduction
MATLAB is a high performance language for technical computing. The name MATLAB
stands for matrix laboratory. Some of the typical uses of MATLAB are given below:
Math and Computation
Algorithm Development
Modeling, Simulation and Prototyping
M-Files
Files that contain code in MATLAB language are called M-Files. You create a M-File
using a text editor and then use them as you would any other MATLAB function or
command. But before using the user defined functions always make sure that the ‘path’ is
set to the current directory. There are two kinds of M-Files:
Scripts, which do not accept input arguments or return output arguments.
Functions, which can accept input and output arguments.
When you invoke a script MATLAB simply executes the commands found in the file.
For example, create a file called ‘SumOfNumbers’ that contains these commands:
% To find the sum of first 10 natural numbers
n = 0;
i = 1;
for i=1:10;
n = n + i;
i = i + 1;
end
n
Go to the command window and set the path to the current directory. Then typing