In the last line of code, I´m trying to order the matrix by the first column.
I want to store in the Array t2tlistsorted ( 100 x 3 ), but I can´t.
t = {
{{2, 1}, {5, 2}},
{{7, 1}, {9, 4}},
{{9, 2}, {6, 6}},
{{5, 4}, {2, 3}},
{{4, 5}, {7, 9}},
{{8, 5}, {2, 4}},
{{3, 7}, {7, 7}},
{{4, 8}, {1, 10}},
{{3, 10}, {10, 7}},
{{9, 10}, {9, 8}}
}
(* t[[i,j,k] i\[Rule]tramo Nºi j\[Rule] \
1=Inicio=Pick-Up 2=Fin=Drop-Off k\[Rule] 1ª o 2ª componente (es \
decir x ó y) *)
Array[t2t, {10, 10}]
Array[t2tlist, {100, 3}]
Array[t2tlistsorted, {100, 3}]
For[i = 1, i <= 10, i++,
For[j = 1, j <= 10, j++,
If[i != j,
t2t[i, j] =
Sqrt[ ( t[[j, 1, 1]] - t[[i, 2, 1]] )^2 + (
t[[j, 1, 2]] - t[[i, 2, 2]] )^2 ], t2t[i, j] = Infinity
(* Calcualmos los Kilometros para ir del tramo i al tramo j,
para lo que recurrimos a la raiz cuadrada de la suma de los \
cuadrados de la diferencia entre el principio(1) del tramo=
trip j y el fin (2) del tramo=trip i *)
]
]
]
For[i = 1, i <= 10, i++,
For[j = 1, j <= 10, j++,
t2tlist[10 (i - 1) + j, 1] = t2t[i, j];
t2tlist[10 (i - 1) + j, 2] = i;
t2tlist[10 (i - 1) + j, 3] = j;
]
]
t2tlistsorted = SortBy[t2tlist, First]
(*SortBy[t2tlist,First] *)
Can you correct my fault?
In this image you can see the output lines
SortBy[t, First]
the desired output? Btw. for me it is not clear whatt2t
and so on is. $\endgroup$