How to repeat array with

조회 수: 7 (최근 30일)
Rajib Deyana
Rajib Deyana 2018년 5월 23일
댓글: Rajib Deyana 2018년 5월 23일
Hi. I have an array for a TSP problem like this A = [1 2 3 4 5] where 1 2 3 shows the city number. I want to know if there's a function in matlab that gives the edge so E = [[1 2], [2 3], [3 4], [4 1]]. Is there a simple way to create such an array like that? since I have 700 arrays with 100x iterations. Thanks

채택된 답변

OCDER
OCDER 2018년 5월 23일
A = 1:4;
E = [A(1) repelem(A(2:end), 2) A(1)];
E =
1 2 2 3 3 4 4 1
  댓글 수: 1
Rajib Deyana
Rajib Deyana 2018년 5월 23일
Great. Thabks

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by