Search code examples
matlabbar-chartmatlab-figure

How to plot bar graph to compare two quantities on y-axis at specific values on x-axis?


I have the following matrix with two rows, each representing a different quantity.

y=[10 35 45; 
   60 70 80];

I want a bar graph for each row at specified values of x which are 25, 50 and 75 i.e. I want to plot 10 and 60 (y-axis) against 25 (on x-axis), 35 and 70 (y-axis) against 50 (x-axis) and 45 and 80 (y-axis) against 75 (x-axis).

I have used:

bar (y) 

But this doesn't allow me to specify values on x-axis. Moreover I've also tried:

bar(x,y);

but I get the following error:

"The length of X must match the number of rows of Y"

Please suggest a solution.


Solution

  • You need transposed y to match the dimensions of x.

    bar(x, y.');
    

    output