假设我有一个矩阵ssout(10X14)匹配和删除行的矩阵
1.15740740740741e-17 1.15740740740741e-18 1.50000000000000e-06 0.990000000000000 0.0900000000000000 3.45000000000000 1.10000000000000 1 2.04312609959835 1.41286525344677e-17 7.06432620699426e-18 0.0100000000000000 10000 0.00100000000000000
1.15740740740741e-17 1.15740740740741e-18 1.50000000000000e-06 0.990000000000000 0.0900000000000000 3.45000000000000 1.10000000000000 1 2.04246490864522 1.41286525344677e-17 7.06432620699426e-18 0.0100000000000000 10000 0.0100000000000000
1.15740740740741e-17 1.15740740740741e-18 1.50000000000000e-06 0.990000000000000 0.0900000000000000 3.45000000000000 1.10000000000000 1 2.04286618115584 1.41286525344677e-17 7.06432620699426e-18 0.0100000000000000 10000 0.100000000000000
1.15740740740741e-17 1.15740740740741e-18 1.50000000000000e-06 0.990000000000000 0.0900000000000000 3.45000000000000 1.10000000000000 1 2.04104656008947 1.41286525344677e-17 7.06432620699426e-18 0.0100000000000000 100000 0.00100000000000000
1.15740740740741e-17 1.15740740740741e-18 6.00000000000000e-06 0.990000000000000 0.0900000000000000 3.45000000000000 1.10000000000000 1 1.99946261970354 9.04233762205933e-16 4.52116877247632e-16 0.0100000000000000 100000 0.00100000000000000
1.15740740740741e-17 1.15740740740741e-18 1.25000000000000e-05 0.990000000000000 0.0900000000000000 3.45000000000000 1.10000000000000 1 1.86355987378850 8.17630355003923e-15 4.08815174015873e-15 0.0100000000000000 100000 0.00100000000000000
1.15740740740741e-17 1.15740740740741e-18 1.50000000000000e-06 0.990000000000000 0.0900000000000000 3.45000000000000 1.10000000000000 1 2.04723993665275 1.41286525344677e-17 7.06432620699426e-18 0.0100000000000000 100000 0.0100000000000000
1.15740740740741e-17 1.15740740740741e-18 6.00000000000000e-06 0.990000000000000 0.0900000000000000 3.45000000000000 1.10000000000000 1 1.99903967606786 9.04233762205933e-16 4.52116877247632e-16 0.0100000000000000 100000 0.0100000000000000
1.15740740740741e-17 1.15740740740741e-18 1.25000000000000e-05 0.990000000000000 0.0900000000000000 3.45000000000000 1.10000000000000 1 1.86368041811290 8.17630355003923e-15 4.08815174015873e-15 0.0100000000000000 100000 0.0100000000000000
1.15740740740741e-17 1.15740740740741e-18 1.50000000000000e-06 0.990000000000000 0.0900000000000000 3.45000000000000 1.10000000000000 1 2.04266773220586 1.41286525344677e-17 7.06432620699426e-18 0.0100000000000000 100000 0.100000000000000
我想通过消除具有匹配没有其他类似的行的行完善这一矩阵。这里的标准是,如果这两行的列[1:2 4:8 12:14]相同,则两行匹配。对于任何一行,如果没有其他行与我们的标准匹配,我们将其删除。
我有这样
ssout = sout;
rows = size(sout,1);
rowss = size(ssout,1);
c1 = 1:2
c2 = 4:8
c3 = 12:14
cout = 0
for i = 1: rows;
for j = 1: rows-1;
if isequal(sout(i,[c1 c2 c3]),ssout(j,[c1 c2 c3]));
[i j]
cout = cout +1 %increase cout each time it finds a match to row i
end
if cout < 2;%included comparison it to itself
sout(i,:) = [];
cout = 0; %reset cout to 0
rows = size(sout,1); %update rows
end
end
end
我知道什么是错的代码,但不知道如何使它工作还没有。任何帮助,将不胜感激!
您可以在'ssout(:,[1:2 4:8 12:14])'''上使用'unique'函数来获得所有唯一行的索引,然后使用索引只获取那些行。 –