ME, Plot

This is ME, and HOWTO Plot ;)

This is how do I plot, Using Matlab.

First of all

   I need some data. If I don't have data, I generate some random data.

Generating Data

   >> a = rand(1, 8)

   a =

    0.8214    0.4447    0.6154    0.7919    0.9218    0.7382    0.1763    0.4057

     Now I have a (1 x 8) vector of random values, I mean a.

   >> b = 1:1:8

   b =

    1     2     3     4     5     6     7     8

     And b is the second vector(or array). Note that for a 2D plot we need pair of values as two 1D arrays with the same dimensions. Each pair, the same index in both arrays, indicates a pixel on the 2D plane.


   1:0.5:8 mean a vector(1D or array) of numbers starting from 1 ending with 8 and with 0.5 diffrence(or step-size).

Quick Start

      Assuming we have two arrays, b contains the indexes or x, and a contains the values or F(x).

      Now, let's do it. Simply ask Matlab to do it for you.

      Dear Matlab please plot a and b, or

   >> plot(b, a)

      and It shows what it did,

    It was really quick :P

A little more

    Let's add something to the plot,


   >> xlabel('Index')
   >> ylabel('Random Values')
   >> title('Plot of 8 Random Values')

Now, what happened,


We could add another graph to current graph, just hold the current graph then plot another one with a different color, and then hold off.

   >> hold all
   >> plot(b, c, 'r')
   >> hold off

That's all.

Somtimes it's needed to point to a special point.

    >> text(b(3),a(3),'\leftarrow Here is something special', 'HorizontalAlignment','left')

Now it's


Now a legend could help the audience to recognize those red and blue plots.

    >> legend('a randoms','c randoms', 2)


     There are different kinds of graphs, for example: Stem, Bar and Stairs



     The sould just replace the plot with stem, bar or stairs. That's all.

     The matlab code that gerenates all of those four graphs is accessible here, mcode.txt, put it in the matlab command line and see them.