Generating random numbers in MATLAB

130 Views Asked by At

Edit: The code is edited and new result is pasted.

I am trying to generate random numbers using randi command in MATLAB. I am generating 100, 1000 and 100,000 random numbers, respectively, between 50 and 100. Following is my code:

clc
clear all
close all  

x = randi([50 100],1,100) % random numbers generated 
subplot(221)
hist(x)                   % ploting these numbers on a histogram
title ('Histogram for 100')


y = randi([50 100],1,1000) % random numbers generated
subplot(222)
hist(y)
title ('Histogram for 1000')


z = randi([50 100],1,100000) % random numbers generated
subplot(223)
hist(z)                   % ploting these numbers on a histogram
title ('Histogram for 100,000')

But I am getting following result:

enter image description here

Is my code right?

1

There are 1 best solutions below

2
On

write subplot command before hist

Like so

> clc
clear all
close all  

x = randi([50 100],1,100) % random numbers generated 
y = randi([50 100],1,1000) % random numbers generated 
z = randi([50 100],1,100000) % random numbers generated 

subplot(221)

hist(x)                   % ploting these numbers on a histogram
title ('Histogram for 100')
subplot(222)

hist(y)
title ('Histogram for 1000')
subplot(223)

hist(z)                   % ploting these numbers on a histogram
title ('Histogram for 100,000')