平面循环擦除随机游走(matlab)

Planar loop erasing random walk (matlab)

this matlab post中,可以找到"Loop erasing random walk"向量问题的解。此问题存在于 "erasing loops" 中,这意味着:删除任何整数重复之间的整数。

示例:

v=[3 1 4 6 7 9 1 22 87 33  35 36 37 35 34] becomes [3 1 22 87 33 35 34].

如何用 2 列矩阵(平面情况)解决同样的问题?

v=[1 1; 2 1; 2 2; 2 3; 3 3; 3 2; 2 2; 2 3; 2 4] should be [1 1; 2 1; 2 2; 2 3; 2 4]

您在问题中链接的线程中的一个答案解决了一维向量的问题。可以使用 real-imaginarty 到复数变换将二维数组转换为一维复数向量(并返回)。因此,以下可能是一个解决方案:

v=[1 1; 2 1; 2 2; 2 3; 3 3; 3 2; 2 2; 2 3; 2 4];
% from your example. note the change in variable name.

% convert the 2-D array into 1-D using real-imag to complex trasnform
u = v*[1;i];

通过 what's published here:

的微不足道的修改解决一维问题
off = false;  % Faster to call function FALSE once
n   = length(u);
use = true(1, n);
i = 1;
while i <= n
    multi = find(u(i:n) == u(i), 1, 'last');
    use((i + 1):(i + multi - 1)) = off;
    i = i + multi;
end

最后,select 来自输入矩阵的 select 行:

v = v(use,:)
%  [1 1;  2 1;  2 2;  2 3;  2 4]