I need to randomly generate 5 points delimited in (0< X< 50) and ( 0< Y< 50)and automatically arrange these in increasing value

 採用された回答

Ameer Hamza
Ameer Hamza 2020 年 11 月 27 日

0 投票

You can sort the randomly generated values
x = sort(randi([1 49], 5, 1));
y = sort(randi([1 49], 5, 1));

7 件のコメント

Sawera Zahra
Sawera Zahra 2020 年 11 月 27 日
What if point should be between P(0,0) and last one P(4,0)
Ameer Hamza
Ameer Hamza 2020 年 11 月 27 日
It means that y axis is constant 0. Following shows a more general approach
x_lims = [0 4];
y_lims = [0 0];
n = 5;
x = sort(rand(n,1)*diff(x_lims)+x_lims(1))
y = sort(rand(n,1)*diff(y_lims)+y_lims(1))
Sawera Zahra
Sawera Zahra 2020 年 11 月 27 日
Thank you for this answer It helped me alot. Now the delimited conditions are changed with (0= <x =< 50)(0= <y =< 50) and z =50
Ameer Hamza
Ameer Hamza 2020 年 11 月 27 日
The above code already shows the pattern
x_lims = [0 50];
y_lims = [0 50];
z_lims = [50 50];
n = 5;
x = sort(rand(n,1)*diff(x_lims)+x_lims(1))
y = sort(rand(n,1)*diff(y_lims)+y_lims(1))
z = sort(rand(n,1)*diff(z_lims)+z_lims(1))
Sawera Zahra
Sawera Zahra 2020 年 11 月 27 日
This seems to be closer to the problem' s solution but starting point and ending points should be P0,0 and P 4, 0 respectively
Sawera Zahra
Sawera Zahra 2020 年 11 月 27 日
Within above x, y, z limits*
Ameer Hamza
Ameer Hamza 2020 年 11 月 27 日
You can use rescale in that case
x_lims = [0 50];
y_lims = [0 50];
z_lims = [50 50];
n = 5;
x = rescale(sort(rand(n,1)), x_lims(1), x_lims(2))
y = rescale(sort(rand(n,1)), y_lims(1), y_lims(2))
z = rescale(sort(rand(n,1)), z_lims(1), z_lims(2))

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

製品

リリース

R2018a

質問済み:

2020 年 11 月 27 日

コメント済み:

2020 年 11 月 27 日

Community Treasure Hunt

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

Start Hunting!

Translated by