urgent question regarding hist3

Hello, I want to plot a 3d histogram in Matlab (hist3 command) with a set of coordinates x,y&z in which each point of x&y has a different value of z. The problem is I have no idea how I should define the value of "z". I would be grateful if someone could help me. Thanks.

 Accepted Answer

Image Analyst
Image Analyst on 25 Dec 2014
hist3() is in the Statistics Toolbox. http://www.mathworks.com/help/stats/hist3.html
There are examples for it. I don't have that toolbox but the help seems to indicate that you give it a list of value pairs in an M-rows by 2-columns matrix. It then counts up the number of times each pair occurs and plots the counts in a "3D"-ish bar chart. So what kind of data do you have? Do you have a list of M-rows by 3-columns, where each column is x, y, or z? If so, what "thing" would you want the function to count? The number of times each x,y,z triplet occurs? What are the x,y,z values anyway? Are they spatial locations where some kind of "event" happened, like a proton emission in a PET scanner or something?

4 Comments

Thanks for your answer. you can assume for example I have four pints which each of these points with coordinate of x and y (x,y), has a different value of z. I want to show value of z for each point with bar chart (3D histogram).
Pints of beer? Sounds like you either have a matrix, like a gray scale image where z is simply the intensity and x and y are the column and row respectively, OR you have an M by 3 list of (x, y, z) values in which case you'll have to turn that into an image with a for loop. Which is it? If it's the list, you can do
rows = round(max(xyz(:,2)))
columns = round(max(xyz(:, 1)))
grayImage = zeros(rows, columns);
for k = 1 : size(xyz, 1)
column = round(xyz(k, 1)); % x value.
row = round(xyz(k, 2)); % y value.
grayLevel = round(xyz(k, 3));
grayImage(row, column) = grayLevel;
end
imshow(grayImage, []);
to turn it into an image (2D matrix). Either way, now that you have an image, you can turn the "z" value into a height of a surface above teh x-y plane by using the surf() function
surf(grayImage);
I really appreciate. Yes you are right. But I want bar chart. I mean for each point (x,y), intensity (z) should be shown by a bar. probably with using hist3 or bar3.
OK. Then use bar3() instead of surf().

Sign in to comment.

More Answers (0)

Tags

Asked:

RSM
on 25 Dec 2014

Commented:

on 25 Dec 2014

Community Treasure Hunt

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

Start Hunting!