generate a table of random number in specific range
14 次查看(过去 30 天)
显示 更早的评论
Hi, i would like to generate a table with specific number of index range.
For example if k =3, the table [3x3] in specific number of range between 1 ,2 and 3 :
1 2 3
2 1 2
3 3 1
0 个评论
回答(2 个)
Image Analyst
2021-2-11
Did you look up rand() in the help? You would have learned how to do things like this:
% Define parameters.
minValue = 1;
maxValue = 3;
rows = 3;
% Create matrices:
m = minValue + (maxValue - minValue) * rand(rows)
% Or with integers:
m2 = randi([minValue, maxValue], rows, rows)
% Or with integers and no repeats:
m3 = reshape(randperm(rows^2), rows, [])
You'll see
m =
1.86651555049844 1.13391009681515 1.53934952237305
1.56954330912193 2.22280802997294 2.14026117843922
2.73713895445458 1.68866727412449 1.26436419354187
m2 =
1 1 3
3 1 2
2 3 1
m3 =
5 9 4
6 2 1
3 7 8
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!