Matlab中如何删除出现n次的整行或者整列?
例如matlab二维数组:123234234234......345345345345......456要求全部删除出现4次的[345]这行,运行结果如下12323423...
例如matlab二维数组:
1 2 3
2 3 4
2 3 4
2 3 4
... ...
3 4 5
3 4 5
3 4 5
3 4 5
... ...
4 5 6
要求全部删除出现4次的[3 4 5] 这行,运行结果如下
1 2 3
2 3 4
2 3 4
2 3 4
... ...
4 5 6
..... 展开
1 2 3
2 3 4
2 3 4
2 3 4
... ...
3 4 5
3 4 5
3 4 5
3 4 5
... ...
4 5 6
要求全部删除出现4次的[3 4 5] 这行,运行结果如下
1 2 3
2 3 4
2 3 4
2 3 4
... ...
4 5 6
..... 展开
展开全部
设这个矩阵为A,那么
a1 = A(:,1);a2 = A(:,2);a3 = A(:,3);
index = a3(a2(a1==3)==4)==5; %依次等于3,4,5
count = 1;
l = length(index);
for i = 1:l-1
if index(i+1)-index = 1
count = count + 1;
else
count = 1
end
if count ==4 %出现四次
count = 1;
i_s = index(i-3);
a1(i_s:l-3) = a1(i_s+3:l);
a2(i_s:l-3) = a2(i_s+3:l);
a3(i_s:l-3) = a3(i_s+3:l);
end
end
A_1 = [a1 a2 a3];
a1 = A(:,1);a2 = A(:,2);a3 = A(:,3);
index = a3(a2(a1==3)==4)==5; %依次等于3,4,5
count = 1;
l = length(index);
for i = 1:l-1
if index(i+1)-index = 1
count = count + 1;
else
count = 1
end
if count ==4 %出现四次
count = 1;
i_s = index(i-3);
a1(i_s:l-3) = a1(i_s+3:l);
a2(i_s:l-3) = a2(i_s+3:l);
a3(i_s:l-3) = a3(i_s+3:l);
end
end
A_1 = [a1 a2 a3];
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询