How do I make a stacked 3-D bar plot from a 3-D matrix?

12 views (last 30 days)
If I have 3-dimensional matrix, how would I plot a bar plot where I want one frame to be a certain level of the 'stacked' bar plot and the next frame stacked on top and so forth?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
Creating a stacked 3-dimensional bar plot is possible using the BAR3 function. A 2-dimensional matrix is collpased when bar3(x,'stacked') option is used. Starting from a 3-D matrix, we grab the first slice of the 3-D matrix and transpose it into a 2-D matrix. Consequently, feed it into bar3. This process will produce the normal output shown in doc bar3.
Next, access the 'xdata' in the of the current axes children and increment it to shift the bars so when BAR3 is called for the next slice of the 3-D matrix, the columns will not overlap. The attached file bar3_stacked.m demonstrates this process.
The following will create a random set of 3D stacked bars using the bar3_stacked function attached to this solution:
a = rand(3,4,5);
bar3_stacked(a);

More Answers (0)

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Products


Release

R14SP1

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!