如何在mathematica中以矩阵的形式跟踪路径

8 wolfram-mathematica

我有一个矩阵,即一个非参差不齐的列表列表,并给出一个坐标列表,例如以{{0,0},{1,1},{2,2},...{5,5}}我的形式,我想跟踪该矩阵中的路径并以图形方式显示结果.路径的彩色带很好.

请帮我在Mathematica中编写这样的函数.非常感谢!

Mar*_*ure 15

这是一种可能性.

pos = {{1, 1}, {1, 2}, {2, 2}, {3, 3},
  {3, 4}, {3, 5}, {4, 5}, {5, 5}};
mat = HankelMatrix[8];
display = Map[Pane[#,{16,20},Alignment->Center]&, mat, {2}];
display = MapAt[Style[#, Background -> Yellow]&, display, pos];
Grid[display, Spacings->{0,0}]
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

如您所述,用管子勾画条目更难.但是,如果我们愿意采用图形基元,那么可以做到.

mat = IdentityMatrix[8];
pos = {{1, 1}, {1, 2}, {2, 2}, {3, 3},
  {3, 4}, {3, 5}, {4, 5}, {5, 5}};
pos = Map[{#[[1]], -#[[2]]} &, pos];
outline = {CapForm["Round"], JoinForm["Round"],
  {AbsoluteThickness[30], Line[pos]},
  {AbsoluteThickness[28], White, Line[pos]}};
disks = Table[{Darker[Yellow, 0.07], Disk[p, 0.25]}, 
  {p, pos}];
numbers = MapIndexed[Style[Text[#, {#2[[1]], -#2[[2]]}, 
  {-0.2, 0.2}], FontSize -> 12] &, mat, {2}];
Graphics[{outline, disks, numbers}, ImageSize -> 300]
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述


Arn*_*ing 10

另一种可能性,使用ItemStyle:

m = RandomInteger[10, {10, 10}];
c = {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}, {5, 6}, {5, 7}, {4, 8}};
Grid[m, ItemStyle -> {Automatic, Automatic, Table[i -> {16, Red}, {i, c}]}]
Run Code Online (Sandbox Code Playgroud)

最终看起来像这样:

Mathematica图形


Ver*_*eia 8

我可能误解了这个问题,但这是我认为你要求的:

coords = Join @@ Array[List, {3, 4}]
{{1, 1}, {1, 2}, {1, 3}, {1, 4}, {2, 1}, {2, 2}, {2, 3}, {2, 4}, {3, 
  1}, {3, 2}, {3, 3}, {3, 4}}

path = RandomSample[coords, Length[coords]]
{{1, 2}, {3, 3}, {2, 2}, {2, 4}, {3, 1}, {1, 4}, {1, 3}, {2, 1}, {3, 
  4}, {3, 2}, {2, 3}, {1, 1}}

labels = Text[StyleForm[#], #] & /@ coords;


Graphics[Line[path], Epilog -> labels]
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述