Random path coordinates in 2D within a unit square

Hi all, I want to generate a random path within a unit square and get the x,y coordinates of 1000 points on it. Can you suggest a way to do it?
start point and the end point should lie diagonally on the opposite corners. For example, if the starting point is (0,0), end point should be (1,1). and if the starting point is (0,1), end point should be (1,0)
I would like to generate random path like this and obtain the coordinates along the path. Please see the attached figure.

回答 (2 件)

James Tursa
James Tursa 2017 年 5 月 4 日
編集済み: James Tursa 2017 年 5 月 4 日

0 投票

Any restrictions on the path? E.g., would 1000 random points suffice:
mypath = rand(1000,2); % <-- each row is an (x,y) point in a unit square

9 件のコメント

KalMandy
KalMandy 2017 年 5 月 4 日
Hi, thanks for the answer.
mypath = rand(1000,2);
xp=mypath(:,1); yp=mypath(:,2);
plot(xp,yp)
I tried this. But the plot gives a mesh-like path. The path should be smooth with a small deviation from the line connecting the starting point and the ending point.
James Tursa
James Tursa 2017 年 5 月 4 日
Please give more details on the path restrictions.
KalMandy
KalMandy 2017 年 5 月 4 日
編集済み: KalMandy 2017 年 5 月 4 日
I would like to generate random path like this and obtain the coordinates along the path. Please see the attached figure.
David Goodmanson
David Goodmanson 2017 年 5 月 5 日
Hi KM, what is the relation between the start and end points and the unit square? From your example, the two points can't be diagonally opposite corners of the square.
KalMandy
KalMandy 2017 年 5 月 5 日
start point and the end point should lie diagonally on the opposite corners. For example, if the starting point is (0,0), end point should be (1,1). and if the starting point is (0,1), end point should be (1,0)
David Goodmanson
David Goodmanson 2017 年 5 月 5 日
except that in the example, some of the paths stray outside the unit square and your original question specifies "within" a unit square. So is outside the unit square all right?
John D'Errico
John D'Errico 2017 年 5 月 5 日
If the first point and the last point are known, then they are not random. But all that means is you really need to generate 998 random points and then append the first and last point.
KalMandy
KalMandy 2017 年 5 月 5 日
@David I want to have all of the path inside the unit square.
KalMandy
KalMandy 2017 年 5 月 5 日
@John yes you are right.

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

Image Analyst
Image Analyst 2017 年 5 月 5 日
編集済み: Image Analyst 2017 年 5 月 5 日

0 投票

See my attached random walk programs and adapt as needed.

カテゴリ

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

タグ

質問済み:

2017 年 5 月 4 日

コメント済み:

2017 年 5 月 5 日

Community Treasure Hunt

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

Start Hunting!

Translated by