Hi,
I am trying to generate 12*2 matrix. The first column should contain random values between [0 5] and the second column should have random values between [5 20]. Can you help me out with this.

 採用された回答

Kodavati Mahendra
Kodavati Mahendra 2018 年 6 月 5 日

0 投票

May be something crude like this?
x = rand(12,2);
x(:,1) = 5*x(:,1);
x(:,2) = 5+15*x(:,2)
rand generates uniformly distributed random number in the interval (0,1).

3 件のコメント

Kodavati Mahendra
Kodavati Mahendra 2018 年 6 月 5 日
Look at the documentation for more , use randi for integers only etc., rand
Melwin Thomas
Melwin Thomas 2018 年 6 月 5 日
Thank you very much. Appreciate your help. It works. I made it a little complicated
a = [0:5]; b = [5:20];
for x=1:12
m = zeros(1:2);
V = repmat([(5.*rand(a)); (5+(20-5).*rand(b))],6);
end
disp(V)
Thank you.
Melwin Thomas
Melwin Thomas 2018 年 6 月 5 日
That's why I was not able to figure it out. Anyways thank you.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File 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