필터 지우기
필터 지우기

Logic issues for creating a random walk

조회 수: 1 (최근 30일)
Andy
Andy 2013년 4월 23일
I have a set of random points plotted. I want to create a random walk between all of these plotted points so they are all visited once and only once. Then i will want to repeat many more random walks to find the best solution.
I am struggling with the logic needed to plot lines between my points and make sure they are only visited once. So any help with that would be appreciated, the rest i can work out.
  댓글 수: 1
Andy
Andy 2013년 4월 23일
I have this so far to try and get my plotting correct.
xCor = rand(1,10)
yCor = rand(1,10)
Cor = [xCor; yCor]
subplot(1,1,1);
plot(xCor,yCor,'r.','MarkerSize',20)
c = randperm(10,10)
x1 = Cor(1,c(1))
y1 = Cor(2,c(1))
x2 = Cor(1,c(2))
y2 = Cor(2,c(2))
hold on;
plot([x1 y1],[x2,y2])
I create my Coordinate set Cor and plot the individual x and y points. I then create a random permutation so that i can select random Columns from Cor. When the numbers are printed out for x1, y1 etc . . they all match with the numbers in Cor and the numbers that were plotted but the plotted line does not relate to any points on my figure . . .despite having the same co ordinates.

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

채택된 답변

Iman Ansari
Iman Ansari 2013년 4월 23일
편집: Iman Ansari 2013년 4월 23일
Hi.
plot([x1 x2],[y1,y2])
For all lines:
xCor = rand(1,10)
yCor = rand(1,10)
Cor = [xCor; yCor]
subplot(1,1,1);
plot(xCor,yCor,'r.','MarkerSize',20)
c = randperm(10,10)
x1 = Cor(1,c(1:9))
y1 = Cor(2,c(1:9))
x2 = Cor(1,c(2:10))
y2 = Cor(2,c(2:10))
hold on;
plot([x1;x2],[y1;y2])
  댓글 수: 1
Andy
Andy 2013년 4월 23일
Thank you, my problem seemed to be i was plotting x1 y1 x2 y2 instead if x1 x2 y1 y2. Your answer also simplifies mine with the colon instead of a loop which is great.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Correlation and Convolution에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by