您在问题中链接的线程中的一个答案解决了一维向量的问题。二维数组可以使用实数到复数变换转换为一维复数向量(并返回)。因此,以下可能是一个解决方案:
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];
对此处发布的内容进行细微修改的一维问题的解决方案:
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
最后,从输入矩阵中选择选定的行:
v = v(use,:)
% [1 1; 2 1; 2 2; 2 3; 2 4]