Generate a 2-dimensional array with random numbers

I want to generate a 2-dimensional array with random numbers. * The first column would contain values from 5 to 1000 and the second column would contain values from 1 to 7.*
I generated a 2-dimensional array with random numbers, but not sure about the bold part of the above paragraph.
Y = 10
Z = 2
result = rand(Y,Z);
result(:,2:2:end) = result(:,2:2:end) .* result(:,2:2:end)

 Accepted Answer

Hi,
does this help:
n = 100; % number of random numbers
A = zeros(n,2);
A(:,1)= randi(996,n,1)+4;
A(:,2)= randi(7,n,1)

3 Comments

the middle "10" means it generates 10 random numbers, right? When I replace it with 100, the code doesn't work.
See edited answer... my mistake- I forgot to preallocate...

Sign in to comment.

More Answers (1)

result(:,1)=randi([1 1000],1,10); result(:,2)=randi([1 7],1,10);
should work
it generates only int though the first parameters are the range of random numbers and the last two the size of the array
look here for more info
https://de.mathworks.com/help/matlab/math/random-integers.html

Categories

Products

Asked:

on 24 Sep 2018

Commented:

on 24 Sep 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!