MATLAB Answers


Question regarding hist3 fucntion

Asked by John
on 10 Jan 2013


I am using the code below to generate this plot.

The variable data contains acceleration and velocity data.

Is there a way to overwrite the the 0,0 bar (i.e velocity = 0 and acceleration = 0) and set it equal to 0? The height of the 0,0 bar is causing the other bars to appear small.

Appreciate any comments.

% Load data
load Data;
% Create the 3D bar chart
% Calculate histogram
nBinsX = 10;
nBinsY = 10;
% Plot histogram
s = get(gca,'child');
zData = get(s,'zData');
colormap gray;
  'zData'     ,zData/length(Data),... % normalize frequency
  'FaceColor' ,'interp',...
  'EdgeColor' ,0.3*[1 1 1],...        % make edges visible at all heights
  'CDataMode' ,'auto');               % color tops according to height
% Labels
title('Velocity VS Acceleration Distribution');
xlabel('Velocity (mph)');
ylabel('Acceleration (m/s^2)');
zlabel('Normalized Frequency');




No products are associated with this question.

1 Answer

Answer by José-Luis
on 10 Jan 2013
Edited by José-Luis
on 10 Jan 2013
 Accepted answer

You could remove the data that are close to [0 0] before getting your histogram

If you want to remove values equal to [0 0];

 Data = Data(~all(Data,2),:);

If you want to remove values close to [0 0];

 your_lim = eps(100); %or some other approximation
 Data = Data(all(abs(Data) > your_lim,2),:); 

Then you can obtain your histogram.


on 10 Jan 2013

Thank you

on 10 Jan 2013

My pleasure.

Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!