1

次のマトリックス:

A = [ -1 1 -1 1 -1 1 0 0 0 0 -1 1 0 0 -1 1 -1 1 0 0 ]

次のようになります。

A = [ -1 1           0 0 0 0 -1 1 0 0 -1 1      0 0 ]
4

1 に答える 1

1

興味深い小さな問題。私はこれがうまくいくと信じています:

A = [-1 1 -1 1 -1 1 0 0 0 0 -1 1 0 0 -1 1 -1 1 0 0]; %# Set up an example vector
I1 = [1, 1, A(1:end-2) - A(3:end)]; %# Index all repetitions of sets of two using zeros
I1(A == 0) = 1; %# Ensure our index doesn't remove any of the 0's from the original vector
Soln = A(I1 ~= 0); %# Obtain solution using nonzero entries of the index
于 2012-11-22T05:39:34.097 に答える