【发布时间】:2016-09-14 03:25:56
【问题描述】:
假设我有一个矩阵 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函数和rows选项来获取所有唯一行的索引,然后使用索引仅获取这些行。
标签: matlab for-loop matrix rows