How do I create a 3D histogram for; x = 1*26, y=1*28, z = 26*28 ?

조회 수: 18 (최근 30일)
Aaron Rampersad
Aaron Rampersad 2016년 3월 21일
이동: Rik 2023년 4월 14일
I would basically like to bin the the 'z' data into ranges of x and y such as the attached picture:
  댓글 수: 2
Joachim Schlosser
Joachim Schlosser 2016년 3월 21일
Please attach some sample data and the code you have tried so far.
Aaron Rampersad
Aaron Rampersad 2016년 3월 22일
I used this code from filexchange but I ended up with a very dense plot attached below:
What I would like to do is place these z-values which is a 26*28 matrix into bins associated with the x and y values

댓글을 달려면 로그인하십시오.

답변 (3개)

Walter Roberson
Walter Roberson 2016년 3월 21일
There are also a lot of histogram programs in the File Exchange.
  댓글 수: 2
Aaron Rampersad
Aaron Rampersad 2016년 3월 21일
Those two commands hist3 and bar3 does not place the Z matrix which is a 26*28 into bins associated with the X and Y matrices.

댓글을 달려면 로그인하십시오.


Image Analyst
Image Analyst 2016년 3월 22일
Aaron, give the x and y data as an N by 2 array, then pass in the number of bins in each direction into the poorly named hist3() to create your 2D histogram
counts = hist3([x, y], [26, 28]);
  댓글 수: 8
Aaron Rampersad
Aaron Rampersad 2016년 3월 26일
편집: Aaron Rampersad 2016년 3월 26일
doesn't the hist3() function only handle x and y vectors of the same size?
My x data is a vector of size 1*26 and my y data is of size 1*28 and my z data is of size 28*26 i.e. a product x and y data inputs.
Image Analyst
Image Analyst 2016년 3월 26일
Well now you'r totally confusing everybody. We though that the x and y were basically ranges that your data could take. So one data point had both an x coordinate, and a y coordinate. And you wanted 28 bins along the y direction, and 26 bins along the x direction. And then "z" would be the counts of how many data points fell into a certain x,y bins. You don't have any z data yet, before taking the histogram, do you? It's to be computed and is the "count" data. If that's not right, then no one has read your mind correctly, and you'll need to explain better and attach your x, y, and z arrays.

댓글을 달려면 로그인하십시오.


Mike Garrity
Mike Garrity 2016년 3월 22일
If you're using R2015b or later, you can use the new histogram2 function.
histogram2(10+5*randn(1e4,1),3*randn(1e4,1),'FaceColor','flat')
  댓글 수: 13
Image Analyst
Image Analyst 2023년 4월 11일
이동: Rik 2023년 4월 14일
You don't need the toolbox to run scatteredInterpolant. You can run it on just a regular 2-D matrix. Here is the main part:
%================================ MAIN PART RIGHT HERE ==============================================
% Create the scattered interpolant. x, y, and gray levels must be column vectors so use (:) to make them column vectors.
% And grayLevels must be double or else an error gets thrown.
F = scatteredInterpolant(xAll(:), yAll(:), double(grayLevelsAll(:)))
% The above line creates an interpolant that fits a surface of the form v = F(x,y).
% Vectors x and y specify the (x,y) coordinates of the sample points.
% v is a vector that contains the sample values associated with the points (x,y).
% Get a grid of points at every pixel location in the RGB image.
[xGrid, yGrid] = meshgrid(1:columns, 1:rows);
xq = xGrid(:);
yq = yGrid(:);
% Evaluate the interpolant at query locations (xq,yq).
vq = F(xq, yq);
fittedImage = reshape(vq, rows, columns);
%================================ END OF MAIN PART ==============================================
grayLevelsAll is the known values of the few locations that you know the values of.
xAll and yAll are your known coordinate values of the locations.
rows and columns are the size of the matrix you want to fill out.
fittedImage is the 2-D array - you don't have to consider it as an image if you don't want to.
CSCh
CSCh 2023년 4월 14일
이동: Rik 2023년 4월 14일
Thank you.
Chris

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Histograms에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by