How can I plot through a histogram the random number generated by matlab.I want to use just rand function.The output of the function is n*m matrix.
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Yeasir Mohammad Akib
el 7 de Jun. de 2015
Respondida: Image Analyst
el 7 de Jun. de 2015
function r = randomness(limit,n,m)
r=floor(1+limit*rand(n,m));
% hist(r(1:n*m),1:limit) %%r(:) is sufficient
% title('Histogram of random numbers')
end
my problem is why hist function is written in that way?
0 comentarios
Respuesta aceptada
Image Analyst
el 7 de Jun. de 2015
The author did r(1:n*m) to get r into a 1-dimensional row vector. If r had remained a 2-D matrix, then hist, like a lot of MATLAB functions, gives you a hist for every column separately. The author didn't want m histograms, they wanted only one histogram so they make r 1-D. However, this could have been done simpler, and in a more MATLAB-ish manner, by simply doing r(:) as their comment mentioned.
The 1:limit was to specify the centers, and hence the number, of the bins.
0 comentarios
Más respuestas (1)
Azzi Abdelmalek
el 7 de Jun. de 2015
limit=10
n=4;
m=3;
r=floor(1+limit*rand(n,m))
hist(r(:))
0 comentarios
Ver también
Categorías
Más información sobre Histograms en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!