Next Post:

Summation Of All Elements Of Matrices And Vectors In MatLab

Creating 2D Bar Charts Effectively In MatLab


In data analyses, bar charts are very good respresentators of different datas. You can also create 2D bar charts in MatLab with ‘bar()’ command. In here, we explain how to create bar charts in MatLab with ‘bar()’ command below.

How To Use ‘bar()’ Command In MatLab?

a = [2 6 3];
b = [1 3 5;4 4 6; 4 6 3];
x = bar(a,b)

Here is a very basic example of use of ‘bar()’ command in Matlab Command Window. We created a vector ‘a’ and a matrix ‘b’. The dimension of matrix 3×3 and length of vector is 3. When you use ‘bar()’ command, write the vector and matrix inside it respectively as above. All the three elements in matrix’s rows will be placed in separate parts of bar graph. And these separated three bars will placed on numbers in vector ‘a’.

If you take a look at the result graph, you will understand the logic.

2D bar chart in Matlab.

The output graph will be like above if you type these codes in MatLab. As you see, separate bar trios are placed upon 2nd, 3rd and 6th places according to elements of vector ‘a’.

a = [2 6 3];
x = bar(a)

Also you can use ‘bar()’ command to create very simple bars that are created one vector or matrix as above. Look at the uotput bar graph below.

Basic 2D bar chart in Matlab.

It is the simplest form of ‘bar()’ command in Matlab.

You can also edit these graphs; add titles, legends and annotations manually.

YOU CAN LEARN MatLab IN MECHANICAL BASE; Click And Start To Learn MatLab!

When you create your vectors and matrices to obtain a bar charts in MatLab, you can enter meaningful values inside them to obtain a good data representations.

Download And Install MatLab R20!

The use of ‘bar()’ command in Matlan to create bar charts is very easy like above. Do not forget to leave your comments and questions about creating bar charts with ‘bar()’ command in Matlab below.

Your precious feedbacks are very important for us.

  • Site Comments

At least 10 characters required.