3

I have an Nx3 matrix in matlab and I'd like to make a 3 dimensional bar graph out of it, where the X and Y axes are determined by the values of first and second columns of the matrix, the height of each bar is the third column in the matrix, and the number of bars is determined by N.

In other words, if "data" is the matrix then:

data(:, 1) % values of X-axis
data(:, 2) % values of Y-axis
data(:, 3) % values of each Z-axis bar

and there should be one bar for each 1:length(data)

How can I do this in MATLAB?

Secondly, as a variant of this, how can I do the same thing, but this time histogram the bars into N bins in each X, Y, Z dimension? I.e. instead of a bar for each point, just histogram the data into those bins in every dimension, and plot a bar for each bin.

thanks very much for your help.

1

1 Answer 1

0

Regarding your 1st question, you can achieve something similar to your request, by:

stem3 (data(:,1), data(:,2), data(:,3), 'marker', 'none', 'linewidth',10)

Not exactly bars, but produces a similar effect.

To plot 'real' bars (such as the ones bar3 plots), I think you'll have to use low-level graphics function such as surface (which is used by bar3 to plot bars).

Regarding your 2nd question, I'm not sure I understand --- if you calculate a histogram for each dimension, you end up with 4-dimensional data --- the bin location for each dimension + the hist count itself. What exactly do you want to plot?

Sign up to request clarification or add additional context in comments.

2 Comments

Makes sense -- how can I then label the X, Y, Z axes of the stem plot? Also, do you know how to make real bars using surface? I don't know how to surface can make bars. Is there an example of this?
The problem with the stem3 plot is that it does not look 3 dimensional -- the bars are just lines and it's hard to see the data

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.