How to group random data
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
If I run the code "rand(4,4)" then that will give me a 4x4 matrix with random numbers between 0 and 1. How do I then get Matlab to group these data into groups like 0 - 0.09, 0.1 - 0.19, 0.2, 0.29, etc, which I can then plot in a histogram.
0 comentarios
Respuesta aceptada
Image Analyst
el 7 de Nov. de 2012
Try this demo. Just copy, paste, and run:
clc; % Clear the command window.
clearvars; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
format longg;
format compact;
fontSize = 20;
data = rand(40,40)
% take hist of data. Use (:) to convert it to a 1D vector.
binWidth = 0.1;
binEdges = 0.0 : binWidth : 1.0;
[counts values] = histc(data(:), binEdges);
bar(binEdges+ binWidth/2, counts, 'BarWidth', 1, 'FaceColor', [.4 .1 .7]);
grid on;
title('Histogram of Data', 'FontSize', fontSize);
xlabel('Bin Value', 'FontSize', fontSize);
ylabel('Counts in the bin', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
7 comentarios
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!