MatLab

Monday, 29 April 2013

Some Basic Operations On Matrices and Vectors.....

The Matlab notation for binary operations on matrices,vectors and there elements are as follows:

  •   + : -  For matrix or element addition
  •   -  : -  For matrix or element subtraction.
  •   .* : - For element wise multiplication
  •   *  : - For matrix multiplication
  •   ./  : - For element wise division.
  •   /   : - For right matrix division (right multiplication by an inverse).
  •   \   : - For left matrix division ( left multiplication by an inverse)

There is also Matlab notation for a few unary operations
  •   .^  : -  For raising an element to a power.
  •   ^   : -  For raising a matrix to a power.
  •   '    : -  For converting to complex conjugate transpose (single forward quote). 
Matlab also has specific notation and symbols for delimiters, separators, grouping, type assignment, and so forth : Essential among these are :
  •  [ ]   : - For vector and Matrix delimiter.
  •  ( )   : - For grouping vector and matrix element indicies, function argument delimiter.
  •  :      : - For index range separator
  •  :      : - For matrix row separator.

  • blank space : - For matrix column element separator.
  • , comma      : - For matrix index separator, function argument separator. 
  • . period        : - For radix expansion separator ( American convention).
  • ' ' single forward quotes : - For demarcation of character strings..

Hope to see you in next tutorial....!!!!

Sunday, 28 April 2013

Functions… the basic necessity of software….


As functions are building block for any software, one should have a good knowledge of atleast some basic functions, so that one can use these functions effectively and in a precise manner.
So what to wait for, let’s start with the basic function “clc”.
                                
“ clc ” function: -

   Clear Command Window

Alternatives: -

As an alternative to the clc function, you can also clear the command window by selecting Edit > Clear Command Window in the MATLAB desktop.

Syntax: -

                  clc


Description: -

clc function clears all inputs and outputs from the Command Window display, giving you a "clean screen” for the fresh use.
After using clc, you cannot use the scroll bar to see the history of functions, but you still can use the up arrow to recall statements from the command history.

Examples: -
     
    1)  Use clc in a MATLAB code file to always display output in the same starting position on the screen.

    2)  Use clc to clear the command window when you are unable to keep track of the functions you used previously or you want a clear screen to work with.

P.S: - Matlab is case sensitive software so take extra care in using the functions.
Hope to see you in next tutorial…!!!

First program…the start to MATLAB atmosphere…



MatLab as a calculator

Have you ever wondered how the scientist makes the precise calculations up to 20 decimal points or how difficult calculations of the eigen value of the matrix of higher orders, etc., etc.

Here I present you the first and very basic use of the Matlab, which 3 in every 5 students are fear off, i.e. calculations. The basic calculations involves addition, subtraction, multiplication, division, square root, etc.

I assumed that now you have good knowledge of different kind of Matlab windows, i.e. how to differentiate different windows.

When you first start Matlab, you will find “>>” symbol in the command window which means you can write whatever you want to write but remember since this software is Matrix based so all the program should be liable and applicable for Matrix.


These are command for some of the basic operations.
     
        1)   >> 20+30 ‘Press enter’
  
 ans  =

    50
        2)   >> 30-20 ‘Press enter’

           ans   =

                       10

        3)   >> 10*5 ‘Press enter’

  ans   =
        
             50
        
        4)   >> 10/5 ‘Press enter’

            ans   =
             
              2

        5)   >> 10\5 ‘Press enter’

            ans   =

             0.5000


Symbol
Name of operation
+
Addition
-
Subtraction
*
Multiplication
/
Forward division
\
Backward division

                               Table: - Symbols and their meaning

P.S:- I would like to advise you that try the above function by your own as well as it help you to learn faster.

Hope to see you in next tutorial…!!!!

First step…Gives you the way to start a long journey…



The goal of this tutorial (also called starting and exiting sessions) is to learn the
First steps:

   ·       How to log on
   ·       Invoke MATLAB
   ·       How to quit MATLAB



1)  Starting MATLAB


After logging into your account, you can enter MATLAB by double-clicking on the MATLAB shortcut icon on your Windows desktop. When you start MATLAB, a special window called the MATLAB desktop appears about which I discussed in the previous tutorial itself. The desktop is a window that contains other windows. The major tools within or accessible from the desktop are:

   ·       The Command Window
   ·       The Command History
   ·       The Workspace
   ·       The Current Directory
   ·       The Help Browser
   ·       The Start button



The graphical interface to the Matlab
Note: - Many new version of the Matlab are now available.
When MATLAB is started for the first time, the screen looks like the one that shown in the above Figure. This illustration also shows the default configuration of the MATLAB desktop. You can customize the arrangement of tools and documents to suit your needs.

2) Invoke MATLAB

You are now faced with the MATLAB desktop on your computer, which contains the prompt (>>) in the Command Window.
Usually, there are 2 types of prompt:
>>” for full version
“EDU>” for educational version
Note: - To simplify the notation, I am using this prompt, >>, as a standard prompt sign, throughout all the tutorials henceforth.

3) Quitting MATLAB


To end your MATLAB session, type quit in the Command Window, or select File à Exit MATLAB in the desktop main menu.

This is the basic start and quitting of the Matlab.
Hope to see you in next tutorial…!!!

Directories…. The address of the programs…



In the previous article on Matlab Desktop, you may have got idea how this software works. You need to save the files for the future use. Now where to save these files? It should be saving in the manner where it can be access by the MATLAB. You can create your own directory/folder anywhere, save your files, and direct MATLAB to find those files. It is convenient to save files in the same folder of the MATLAB where its application files are installed because it gives all the user written files an automatically accessible by MATLAB.
But I always prefer to save my written files in the folder which contains my data about the relevant project as MATLAB also provides you an alternative to above method i.e. change directory command when you press ‘run button’ , which looks like the following window.

                  

  •          Change folder Option: - This option changes the current directory of the Matlab and will only allow you to access files of that folder/directory.


  •          Add to Path: - This option unable you to add the path of your program to the existing list of the path/directories in the Matlab. Due to this option , you will be able to access the current directory as well as the folder in which your current program is.


  •          Cancel: - To cancel your operation.


  •          Help: - Help provides the necessary information of how you can use this dialog box in case you find it difficult or confusing.


You can also change the path command or change the working directory of MATLAB to the desired directory with the cd command.

Let us see how to do it in PC’s
Step-1
Create a folder inside the MATLAB folder and save your files there.

Step-2
Create a file in notepad or any word doc. And save this file with the extension of “.m”, let us take “fun.m” and now launch MATLAB by double-clicking on the ‘fun.m’ file in your folder.

Step-3
This way Matlab automatically accesses all files in your folder. You can open, write and save M-files by selecting appropriate commands from the File menu in MATLAB.

Types of MATLAB file extension….a pet name to recognize the file type…



Since all the files which we save have one or other extension, with which the computer recognize in which platform /software it needs to open that file for future uses. The same applies for MATLAB. Here are the important file extensions which MATLAB provides.
They are as follow….

1)     Figure Files: -
Extension: -“.fig”
These files contains MATLAB figure. He plot, figure, image, etc. are stored with the extension of .fig by default. (You can specify the format of image you would like to store by selecting the format type from the drop down list which appears while saving the figure.)
2)     M-Files: -
Extension: - “.m” 
M-Files are standard ASCII text files. There are two types of these files
a)     Script files
b)    Function files
The built- functions in MATLAB are M-files most of which reside on computer in precompiled format. It may possible that you may not find the built-in function as per your requirement. In that case, you can create your own function which can be later used anywhere and whenever required in MATLAB program. 

3)     Mat- Files: -
            Extension: - “.mat”
They are MATLAB binary file for storing variables. These files can also be easily transfer to other systems.  They contain a machine signature in the file header. Matlab checks the signature when it loads a file and, if a signature indicates that a file is foreign, performs the necessary conversion.
4)     Mex Files: -
Extension: - “.mex…” 
Matlab provides an interface to external programs written in the C and FORTAN languages.
You can call C or FORTAN subroutines from MATLAB as if they were built in functions. These callable programs are referred to as MEX-files. They are dynamically linked subroutines that the MATLAB interpreter can automatically load and execute.
(Platform specific, e.g. ".mexmac" for the Mac, ".mexglx" for Linux, etc.)

Third-party File extension
1)     .jkt 
GPU Cache file generated by Jacket for MATLAB (AccelerEyes)
2)     .mum 
MATLAB CAPE-OPEN Unit Operation Model File (AmsterCHEM)

P.S: - The first four file extensions are much of our use.
Hope to see you in next tutorial….!!!

Toolboxes in Matlab...In other words heart of Matlab.....


Toolboxes
Since all software have built in tools, which provides a great aid to a user to work with it, so do Matlab has. They provide access to additional mathematical function library on specific topics. In all Matlab provides 38 toolboxes which provide a flexible handling with software.The following are some of the toolboxes viz.
  • Ø  Communications toolbox
  • Ø  Control System toolbox
  • Ø  DSP Blockset
  • Ø  Symbolic Math Toolbox
  • Ø  Aerospace Toolbox
  • Ø  Bioinformatics Toolbox
  • Ø  Computer Vision Toolbox
  • Ø  Fuzzy logic Toolbox
  • Ø  Financial Toolbox
  • Ø  OPC Toolbox
  • Ø  Robust Control Toolbox
  • Ø  Curve Fitting Toolbox
  • Ø  Data Acquisition Toolbox
  • Ø  Datafeed Toolbox
  • Ø  Optimization Toolbox
  • Ø  Neural Network Toolbox
  • Ø  Mapping Toolbox
  • Ø  Model Predictive Toolbox
  • Ø  Simulink
  • Ø  Curve Fitting Toolbox
  • Ø  Image Processing Toolbox
  • Ø  Image Acquisition Toolbox
  • Ø  Filter Design Toolbox
  • Ø  Database Toolbox
  • Ø  Econometrics Toolbox
  • Ø  Embedded IDE Link CC
  •  Filter Design Toolbox

  •         Fixed- Point Toolbox
  •         Genetic Algorithm and Direct Search Toolbox
  •     Signal Processing toolbox….

and many more……
Cant include all the toolboxes but don’t worry , will let you know when the appropriate time comes.
As you can notice that almost all kind of the toolbox are present in Matlab, which you can think. Please don’t be scared with the names of the toolboxes because as we will move ahead in our tutorials, you will have a great fun working with this toolboxes….
Hope to see you in next tutorial..!!!

Sunday, 14 April 2013

Matlab Desktop….In other words Matlab Windows…


One should have a clear knowledge about the windows of MATLAB before starting to work on it.

MATLAB includes a variety of different windows for displaying different types of information and performing special tasks. Each window can generally be opened/ closed, docked in the main window or popped out, and repositioned/resized depending on current needs/preferences. The Window menu helps you navigate between the currently open windows, while the Desktop menu lets you open new windows (which can also be done from the command window).


Command Window: -The window where you type commands and non-graphic output is displayed. A `>>' prompt shows you the system is ready for input. The lower left hand corner of the main window also displays `Ready' or `Busy' when the system is waiting or calculating. Previous commands can be accessed using the up arrow to save typing and reduce errors. Typing a few characters restricts this function to commands beginning with those characters.


Command History: - Records commands given that session and recent sessions. Can be used for reference or to copy and paste commands.


Workspace: - Shows the all the variables that you have currently defined and some basic information about each one, including its dimensions, minimum, and maximum values. The icons at the top of the window allow you to perform various basic tasks on variables, creating, saving, deleting, plotting, etc. Double-clicking on a variable opens it in the Variable or Array Editor. All the variables that you've defined can be saved from one session to another using File>Save Workspace As (Ctrl-S). The extension for a workspace file is .mat.


Current Directory: - The directory (folder) that MATLAB is currently working in. This is where anything you save will go by default, and it will also influence what files MATLAB can see. You won't be able to run a script that you saved that you saved in a different directory (unless you give the full directory path), but you can run one that's in a sub-directory. The Current Directory bar at the top centre of the main window lets you change directory in the usual fashion -- you can also use the UNIX commands cd and pwd to navigate through directories. The Current Directory window shows a list of all the files in the current directory.



Editor:-  The window where you edit m-files --the files that hold scripts and functions that you've defined or are editing--  and includes most standard word-processing options and keyboard shortcuts. It can be opened by typing edit in the Command Window. Typing edit myfile will open myfile.m for editing. Multiple files are generally opened as tabs in the same editor window, but they can also be tiled for side by side comparison. Orange warnings and red errors appear as underlining and as bars in the margin. Hovering over them provides more information; clicking on the bar takes you to the relevant bit of text. Also remember that MATLAB runs the last saved version of a file, so you have to save before any changes take effect.



Variable Editor or Array Editor: - Opens variables in an Excel-like format, and is useful for checking what data is in which column/row, checking that value is where you meant it to be, etc. Data can also be edited or created in this window. Double-clicking on a variable in the Workspace will open it for editing. Multiple variables are usually opened as tabs, but can also be tiled for side by side comparison.



Figure Editor: - MATLAB opens figures in separate windows, which includes the ability to fine-tune the appearance of the plot, zoom, etc. You can also use the Data Cursor to extract values and save them to the Workspace. See the Help documentation for further detail. The figures can also be saved in a wide variety of formats -- it's usually a good idea to save them as an m-file (File>Generate M-file) if there's any chance at all you might want to modify the figure later and you haven't already saved the generating code in a m-file.



MATLAB Help: - MATLAB’s help documentation is very good, and can tell you pretty much any-thing you need to know. Help>Product Help opens the Help Window, which works largely like a web browser, including forward and back buttons. Use the Contents tab for help oriented around a broad topic (most of what you need will be under the MATLAB heading, and then probably Getting Starting or Graphics) --Search or Index for more specific queries (e.g. interpolating values, polynomial fit, etc.). The `see also' at the end of each file is very useful if you haven't found quite the right thing. It can also suggest better ways of doing things. Typing help commandname in the Command Window will also bring up the help file for that command.


Hope to see you in next tutorial....!!!!

MatLab .....Where every imagination can be given shape.....


If I say that the world is made up of matrix and anything can be solved with the use of matrix, just as it is pictured in one of the best movie “Matrix” (including all three parts), would you believe that???...If your answer is ‘No’, then this software can prove you wrong.    

MATLAB, as the name suggest, stands for Matrix Laboratory. This software is the one of the funniest of its kind and is very easy to learn. It is a high performance language for technical computing. It integrates computation, visualization and programming environment. Or you can just consider that everything can be done with this software which one can imagine to do in other software.


This software can be used in various fields viz. Engineering, Medical, Art, etc. etc. etc….
MATLAB provides you all those stuffs to do which you can do in any other software like GUI , Image Processing, Image Acquisition, Music Mixing, Music Player, Movie Player, Photo Editing, Sending Mails, etc. etc…. One can learn this software by using HELP of the MATLAB. Then you will be wondering why to waste time on learning by this tutorial???
The simple answer for this is as a researcher I faced a lots of problem to learn the stuffs about MATLAB as a beginner as was not knowing from where to start and what to start. So basically the following tutorials are just the experience shared by one small dot to one of the bright line of the future world.

   
This software can be treated as a building block for learning any new software. One who is good at MATLAB , will surely will never face a problem to learn any new software easily.
MATLAB has many advantages compared to the conventional computer languages (C, FORTAN), for solving technical problems. It is an interactive system whose basic data is an array that does not require dimensioning.


 It has powerful built-in routines that enable a very wide variety of computations. It also has easy to use graphics commands that make the visualization of results immediately available. Specific applications are collected in packages referred to as toolbox. There are toolboxes for signal processing, symbolic computation, control theory, simulation, optimization, and several other fields of applied science and engineering.

Hope to see you in next tutorial.....!!!!