假設我有一個矩陣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'函數來獲得所有唯一行的索引,然後使用索引只獲取那些行。 –