08/07/2014

Colon Operator è :
It is easy to create small matrixes, row vectors and column vectors but what happens when these array contain hundreds of values, it’s just practically not possible to write each value, for these MATLAB provides us with a special strong operator i.e Colon operator, represented as :
           It is used to declare a large range of values with some increment(according to demand) and correspondingly large ranged row vector, column vector and a matrix can be created using this strong operator i.e colon operator.
General form of colon operator,  INITIALVALUE:INCREMENT:FINALVALUE
By default increment is 1 if we will not mention increment to MATLAB for this we can also use the general form as INITIALVALUE:FINALVALUE, but we can set increment according to our demand for this we have to use the general form of colon operator as discussed above.
 ÄFor example we set:
      Initial value=1|  Increment=1 |  Final value=10
      So from initial to final value step by step increment will be like this described below.
                 Use of Colon Operator in MATLAB as a shortcut key.

                   
 ÄMATLAB declaration and result of colon operator :
%declaration of row vector using colon operator.
x=1:15 % here by default increment will be 1,we can also declare it as x=[1:15].
b=1:0.5:15 % here have limited MATLAB to take an increment of 0.5 each time, till final value.

%declaration of column vector using colon operator.
c=[1:15]' % by default increment is 1.
d=[1:0.5:15]'% MATLAB become limited to take an increment of 0.5 each time

%matrix declaration using colon operator.
g=[d d] % it will generate 30*2 matrix.

? To download above script click below:

script m-file for matrix,row vector and column vector declaration using colon operator

0 comments:

Post a Comment

Blog Archive

Popular Posts