In this matlab colon operator example we will show how it can be used for calculating series of values using values stored in a vector using colon operator. Suppose we want to calculate the power dissipated in a resistor due to various current values. The power dissipated in a resistor is given by,

P = I

Now suppose we want to calculate the Power P for various current I as follows

I is 0A, 2A, 4A, 6A, 8A and 10A

Now this current can be expressed in Matlab using the colon operator as follows,

I = (0:2:10)

Let the Resistance of the resistor be fixed at 10Ohm. Then a matlab script for calculating the Power P for the currents is,

R=10; I=(0:2:10);

V=I.*R;

p=(i.^2)*R;

p =

0 40 160 360 640 1000

Since we also calculated the voltage V it is calculated as,

V =

0 20 40 60 80 100

So in this way you can use the matlab colon operator.

P = I

^{2}RNow suppose we want to calculate the Power P for various current I as follows

I is 0A, 2A, 4A, 6A, 8A and 10A

Now this current can be expressed in Matlab using the colon operator as follows,

I = (0:2:10)

Let the Resistance of the resistor be fixed at 10Ohm. Then a matlab script for calculating the Power P for the currents is,

R=10; I=(0:2:10);

V=I.*R;

p=(i.^2)*R;

p =

0 40 160 360 640 1000

Since we also calculated the voltage V it is calculated as,

V =

0 20 40 60 80 100

So in this way you can use the matlab colon operator.

## No Comment to " Example of using colon operator in Matlab "