access the multidimensional data using linear index

조회 수: 7 (최근 30일)
praveensilvi
praveensilvi 2019년 1월 28일
답변: Walter Roberson 2019년 1월 28일
i need to calculate the distance by using the route for travelling saleman problem. im having my distance value in one matrix 'DIST' and route is in another matrix 'path'
it is an 5 cities tsp problem.
DIST = [ 0 2 5 8 3
.............
............
7 6 3 4 0] it is a 5 x 5 matrix
path =[ 1 2 3 4 5
1 2 3 5 4
.......
.......
5 4 3 2 1] it is a 120 x 5 matrix
for each row of path get the value from DIST [eg:1 2 in path it will get the value 2 from the DIST]
kindly hlep me code this.....
  댓글 수: 2
madhan ravi
madhan ravi 2019년 1월 28일
편집: madhan ravi 2019년 1월 28일
Can you give an explicit example of your desired output?
praveensilvi
praveensilvi 2019년 1월 28일
take 1st row of path [1 2 3 4 5] it means 1st row and 2nd column of th DIST value it takes (2) then 2nd row and 3rd column of the DIST likewise do it for all and store the values in one matrix

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

답변 (2개)

KSSV
KSSV 2019년 1월 28일
Read about ind2sub and sub2ind.

Walter Roberson
Walter Roberson 2019년 1월 28일

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by