-1

I have a dataset in the following format:

UID     Lat    Long   LocID

u1      lt1    lg1    l1

u1      lt2    lg2    l2

u1      lt3    lg3    l3

u2      lt4    lg4    l4

u3      lt1    lg1    l1

u3      lt4    lg4    l4

From here I need to generate a LocID-LocID un-directed graph. For this I need a weighted matrix in the following format.

    0           d(l1,l2)        0           0

  d(l2,1)          0         d(l2,l3)    d(l2,l4)

    0           d(l3,l2)        0           0

  d(l4,l1)      d(l4,l2)        0           0 

Since, user-u1 is present at locations l1, l2 and l3, hence i consider them as visible edges in the graph. And hence, there exists edge from l1 -> l2 and l2->l3. From the given example, there exists 4 edges.

l1 -> l2 ; l2->l3 [For user u1]
l2->l4 [For user u2]
l1 -> l4 [For user u3]

here weight of each edge between two LocID is computed from the given Latitude and Longitude information. Like, d(l1,l2) = distance between LocID-1 and LocID-1 = distance between (lt1,lg1) and (lt2,lg2)

Distance calculation can be done by using haversine formula. So, that is not a problem. I need to perform this task in matlab. Can anyone please help me.... thanks in advance....

Pramit
  • 23
  • 7
  • I don't understand the question. Is the question how to create a matrix with such a pattern? I don't understand the pattern. Is the distance already defined? – Daniel Mar 12 '14 at 14:07
  • possible duplicate of [matlab adjacency list to adjacency matrix](http://stackoverflow.com/questions/19295931/matlab-adjacency-list-to-adjacency-matrix) – tashuhka Mar 12 '14 at 14:11
  • edit the question for more details... – Pramit Mar 12 '14 at 14:27
  • Much clearer now, but still some questions. Why is your distance matrix not symmetric? There is `d(l4,l1)` but not `d(l1,l4)`. Where in your data do you get this information: `l2->l4 [For user u2]`?. In which format is the data provided? `d(l2,1)` is obviously a typo. What is `d`? Is it already defined? – Daniel Mar 12 '14 at 14:50

1 Answers1

0

You might be looking for the pdist function in the statistics toolbox.

It calculates distances between points with different distance measures, also custom functions are allowed (as handles).

jpjacobs
  • 9,359
  • 36
  • 45
  • Thank for your suggestions. But, i am not concerned about the distance calculation. I need the weighted adjacency matrix. – Pramit Mar 12 '14 at 14:34
  • That is exactly what pdist hands you. My point is indeed that it can handle any distance metric you'd want to plug in. – jpjacobs Mar 12 '14 at 14:55