3D Histogram of 50x50 data
    조회 수: 8 (최근 30일)
  
       이전 댓글 표시
    
Hello, I am looking to plot a 3D histogram (like the one in the attached snippet) in MATLAB. I have x and y axes which are 50 bins each, one is ranging from -4000 and 4000 and the other one from 0 and 8000. I just need to plot the binned values (as z) which is 50x50.
Thanks in advance.
댓글 수: 0
채택된 답변
  the cyclist
      
      
 2023년 6월 3일
        댓글 수: 3
  the cyclist
      
      
 2023년 6월 3일
				% Read the data from file
xyz = readmatrix("Histogram2_sample.xlsx");
% Get the x, y, and z values
x = xyz(2:end,1);
y = xyz(1,2:end)'; % Transpose to get a column vector
z = xyz(2:end,2:end);
% Flip x and z, because histogram algorithm requires increasing values
x = flipud(x);
z = flipud(z);
% Plot
figure
histogram2('XBinEdges',[x; x(end)+160],'YBinEdges',[y; y(end)+160],'BinCounts',z)
% Change the view to make the perspective similar to posted image
set(gca,"View",[145 30])
추가 답변 (1개)
  Diwakar Diwakar
      
 2023년 6월 4일
        This code may help you:
% Generate some random data
data = randn(1000, 2) .* [4000, 8000] + [0, 4000];
% Define the bin edges
x_edges = linspace(-4000, 4000, 51);
y_edges = linspace(0, 8000, 51);
% Compute the histogram
histogram2D = hist3(data, 'Edges', {x_edges, y_edges});
% Plot the 3D histogram
figure;
bar3(histogram2D);
xlabel('X');
ylabel('Y');
zlabel('Count');
title('3D Histogram');
% Customize the plot appearance
colormap jet;  % Change the color map if desired
colorbar;  % Add a color bar
댓글 수: 0
참고 항목
카테고리
				Help Center 및 File Exchange에서 Histograms에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




