Archive for the ‘Matlab’ Category

Matlab tutorial index

Posted on the May 26th, 2010 under Matlab, Matlab Tutorial by Student

Matlab Tutorial 1 – The basic features
Matlab Tutorial 2 – Vectors and matrices
Matlab Tutorial 3 – Built-in functions
Matlab Tutorial 4 – Plotting
Matlab Tutorial 5 – M-files: Scripts and functions
Matlab Tutorial 6 – Loops
Matlab Tutorial 7 – If statement
Matlab Tutorial 8 – Polynomials in MATLAB
Matlab Tutorial 9 – Numerical Methods
Matlab Tutorial 10 – Matlab GUI tutorial

Matlab Tutorial 10 – Matlab GUI tutorial

Posted on the May 26th, 2010 under Matlab, Matlab Tutorial by Student

Matlab LogoWhy use a GUI in MATLAB? The main reason GUIs are used is because it makes things simple for the end-users of the program. If GUIs were not used, people would have to work from the command line interface, which can be extremely difficult and fustrating. Imagine if you had to input text commands to operate your web browser (yes, your web browser is a GUI too!). It wouldn’t be very practical would it? In this tutorial, we will create a simple GUI that will add together two numbers, displaying the answer in a designated text field.

Launching GUI from Command Prompt

This tutorial is written for those with little or no experience creating a MATLAB GUI (Graphical User Interface). Basic knowledge of MATLAB is not required, but recommended. MATLAB version 2007a is used in writing this tutorial. Both earlier versions and new versions should be compatible as well (as long as it isn’t too outdated). Lets get started!

Matlab Tutorial 9 – Numerical Methods

Posted on the May 25th, 2010 under Matlab, Matlab Tutorial by Student

In this tutorial we mention some useful commands that are used in approximating various quantities of interest.

We already saw that MATLAB can find the roots of a polynomial. Suppose we are interested in finding the root(s) of a general non-linear function. This can be done in MATLAB through the command fzero, which is used to approximate the root of a function of one variable, given an initial guess. We must first create an m-file that describes the function we are interested in, and then invoke the fzero command with the name of that function and an initial guess as input. Consider finding the root(s) of f(x) = ex – x2. We create the m-file called eff.m as seen below.

Matlab Tutorial 8 – Polynomials in MATLAB

Posted on the May 25th, 2010 under Matlab, Matlab Tutorial by Student

Even though MATLAB is a numerical package, it has capabilities for handling polynomials. In MATLAB, a polynomial is represented by a vector containing its coefficients in descending order. For instance, the following polynomial

Matlab Tutorial 7 – If statement

Posted on the May 25th, 2010 under Matlab, Matlab Tutorial by Student

There are times when you would like your algorithm/code to make a decision, and the “if” statement is the way to do it. The general syntax in MATLAB is as follows :

Matlab Tutorial 6 – Loops

Posted on the May 25th, 2010 under Matlab, Matlab Tutorial by Student

We will now cover some commands for creating loops, which are not only used in writing m-files, but in regular MATLAB sessions as well. The examples that we will give will include both situations. The two types of loops that we will discuss are “for” and “while” loops. Both loop structures in MATLAB start with a keyword such as for, or while and they end with the word end.

Matlab Tutorial 5 – M-files: Scripts and functions

Posted on the May 24th, 2010 under Matlab, Matlab Tutorial by Student

To take advantage of MATLAB’s full capabilities, we need to know how to construct long (and sometimes complex) sequences of statements. This can be done by writing the commands in a file and calling it from within MATLAB. Such files are called “m-files” because they must have the filename extension “ .m“. This extension is required in order for these files to be interpreted by MATLAB.

Matlab Tutorial 4 – Plotting

Posted on the May 22nd, 2010 under Matlab, Matlab Tutorial by Student

We end our discussion on the basic features of MATLAB by introducing the commands for data visualization (i.e. plotting). By typing help plot you can see the various capabilities of this main command for two-dimensional plotting, some of which will be illustrated below.

If x and y are two vectors of the same length then plot(x,y) plots x versus y.

Matlab Tutorial 3 – Built-in functions

Posted on the May 21st, 2010 under Matlab, Matlab Tutorial by Student

There are numerous built-in functions (i.e. commands) in MATLAB. We will mention a few of them in this section by separating them into categories.
Scalar Functions

Certain MATLAB functions are essentially used on scalars, but operate element-wise when applied to a matrix (or vector). They are summarized in the table below.

Matlab Tutorial 2 – Vectors and matrices

Posted on the May 21st, 2010 under Matlab, Matlab Tutorial by Student

We have already seen how to define a vector and assign a variable name to it. Often it is useful to define vectors (and matrices) that contain equally spaced entries. This can be done by specifying the first entry, an increment, and the last entry. MATLAB will automatically figure out how many entries you need and their values. For example, to create a vector whose entries are 0,1,2,3,…,7, 8, you can type

>> u=[0:8]
 
u =
 
     0     1     2     3     4     5     6     7     8