Creating a histogram,
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
What command should I use to create a histogram of the data in x, with 7 bins that start on the 10's?
0 comentarios
Respuestas (3)
David Hill
el 9 de Abr. de 2021
Use histogram(), the matlab documentation is quite good.
0 comentarios
Mattes Köppe
el 9 de Abr. de 2021
To crate a Histogram use
histogram(x)
Since you want to specifiy the number of bins you can use
histogram(X,nbins)
In your case nbins would be 7.
The edges of the bins are choosen automatically depending on your inputvector x or u can specify them using
histogram(X,edges)
0 comentarios
Image Analyst
el 9 de Abr. de 2021
Try this:
% Create a hundred thousand values ranging from 0 - 1000.
numValues = 100000;
r = 1000 * rand(numValues, 1);
% Define bin edges on "10" boundaries, and get 7 bins:
edges = [0 : 10 : 70]
% Note: any x values beyond 70 will be totally ignored - they will not be lumped into the rightmost bin.
% If you want ALL the values, make the last bin inf
% edges = [0 : 10 : 70, inf]
h = histogram(r, edges)
% Let's see how many values got considered:
fprintf('The data has %d values. This histogram has %d total counts in it.\n', ...
numValues, sum(h.Values));
% Make the plot fancy:
grid on;
title('Histogram of x', 'FontSize', 18);
xlabel('x value', 'FontSize', 18);
ylabel('Counts', 'FontSize', 18);
ax = gca; % Get handle to current axes.
% Let's have the tick marks go outside the graph instead of poking inwards in to the bar.
ax.TickDir = 'out';
0 comentarios
Ver también
Categorías
Más información sobre Histograms en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!