Saturday, January 05, 2013

MATLAB TUTORIAL 1- GETTING STARTED




Hi friends….!! This time we are here to start our journey of learning MATLAB , a very useful and powerful software for electronics lovers and others too . So in this article first of all we will discuss about some basics of  MATLAB …..lets start…

DESKTOP INTRODUCTION


This is the first window which u will see after starting MATLAB.






Now here you can see these sections-

CURRENT FOLDER- In this section you can you can access your files to use.

COMMAND WINDOW- Here you will enter your commands in command line started with (>>)

WORKSPACE- This section explore all the data which you create or import from files.

COMMAND HISTORY- It is a very important panel , here you can view your commands and you can can rerun those commands too.


USE OF VARIABLES

Starting from very basic , you can se MATLAB as a simple calculator. For this you have to enter the desired mathematical expression in command line , say it is 1+2*5, so just type it in command line.

>> 1+2*5
Press enter and MATLAB will respond as

ans =

    11

Now you can see we have not assigned any variable and MATLAB used a default variable ans for this calculation now you can choose any variable for it, say ‘x’ . So we will type

>> x=1=2*5
And MATLAB will respond as

x =
       11 

Now this variable can be used for further calculations as well like,

>> y=x*5
This time MATLAB will respond as

y =
      55

 This is the list for some basic arithmetic  operation commands to be used for simple calculations

+     addition
 -     subtraction
*     multiply
/    divide


HIERARCHY OF ARITHMATICAL OPERATIONS

MATLAB performs the arithmetical operation in same manner as taught in high school algebra first parentheses then exponents (from left to right), then division(left to right), multiplication( left to right), addition( left to right), sand at last subtraction ( left to right).


Use of parentheses

Like simple mathematics calculations parentheses can also be used in MATLAB for solving expressions and use of parentheses will give a different answer of the expression.

For example-  








In matlab it becomes 

>> 1/(2+4)+4/5*6/7

ans =
           0.8524

But without parentheses it will be

>> 1/2 +4+4/5*6/7

ans =
          5.1857

So be careful using parentheses.

ERROR MESSAGE AND CORRECTION

Some times an error message displays if you will use a wrong command like

>> 2x
??? 2x
     |
Error: Unexpected MATLAB expression.

To correct this mistake you can obviously retype or you can edit and re execute same command by using UP ARROW KEY.

MANAGING THE WORKSPACE

 clear command

>>clear
clear command is used to clear all the variables from the workspace, sometime similar variable in two different operations can cause ambiguity.

 who and whos command

>> who
This command gives detail of all the variable in the memory. whos is more specific one and provides more details.

SAVING THE WORK SESSION

diary , diary off and diary on command

during your work if you want to save any particular work session you can use diary command as

>> diary
Or
>> diary Filename

Here filename can be any arbitrary name chosen by you.

diary command is used to save entire MATLAB session but you can stop recording at any instant by using diary off command and you can again start it with diary on command. The created file is a simple text file can be opened and edited in any editor.

HOW TO USE MULTIPLE COMMAND IN SINGLE LINE

MATLAB provides us facility to use multiple commands in single line. These different commands should be separated by comma(,) or semicolon(;) like


>> a=9;c=a+9,d=c+9   

c =
    18
d =
     27

CLEARING , ABORTING AND CONTINUING

>> clc       

 Clearing the command window

>> ctrl
Aborting the MATLAB session

>>…
To continue a line.

GETTING HELP

To get help about various MATLAB operations you can use HELP BROWSER of matlab by clicking on the HELP BROWSER ICON
On the other hand you can use help command

>>help

So friends these are the basics of MATLAB, I hope it was useful for you …..we will learn about various commands and operations in upcoming tutorials. If you have any query , doubt or critical views just leave a comment here………


        THNX

No comments:

Post a Comment