MATLAB: Bar Graph Stacked with Negative and Positive values

bargraphplotstack

Hi.
I'm trying to get a plot to act like the graph function in excel that stacks values together. It does this by putting all positive values on the positive part of the axis, and the negative values on the negative side.
Unfortunatly when I use bar(X,'stack') with matlab it doesn't do this.
Is there any way to get this same functionality? Thanks.

Best Answer

I think that I figured this out. The trick is to do two graphs and to seperate out the positive and negative values:
>> X = rand(4,3) - 0.5;
>> Xneg = X;
>> Xneg(Xneg>0) = 0;
>> Xpos = X;
>> Xpos(Xpos<0) = 0;
>> hold on
>> bar(Xneg,'stack')
>> bar(Xpos,'stack')
>> hold off