필터 지우기
필터 지우기

Generate a 2-dimensional array with random numbers

조회 수: 48 (최근 30일)
Hoque
Hoque 2018년 9월 24일
댓글: Hoque 2018년 9월 24일
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)

채택된 답변

Stephan
Stephan 2018년 9월 24일
편집: Stephan 2018년 9월 24일
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
Stephan
Stephan 2018년 9월 24일
See edited answer... my mistake- I forgot to preallocate...
Hoque
Hoque 2018년 9월 24일
Thanks! :)

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Joel Meyer Espinoza
Joel Meyer Espinoza 2018년 9월 24일
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
  댓글 수: 1
Joel Meyer Espinoza
Joel Meyer Espinoza 2018년 9월 24일
make sure to hit enter after the first semicolon in the code

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by