How to filter the rows i donot want in a matrix
4 次查看(过去 30 天)
显示 更早的评论
there is a matrix like
A=[ 0 1 0;
0 2 0;
1 0 0;
1 0 1];
compering A(1,:) and A(2,:), i choose [0 2 0];compering A(3,:) and A(4,:), i choose [1 0 1].
the final matrix i want is
A=[ 0 2 0;
1 0 1];
This is just a simple example, if the matrix is M*N, how to use matlab code to get the matrix i want.
6 个评论
采纳的回答
Azzi Abdelmalek
2014-4-2
编辑:Azzi Abdelmalek
2014-4-3
Edit
A=[1 1 0;0 2 0;1 0 0;1 0 1]
n=size(A,1);
k=1;
while k<n
if any(all(bsxfun(@le,A(k,:),A(k+1:end,:)),2))
A(k,:)=[];
k=k-1;
end
k=k+1;
n=size(A,1);
end
A
7 个评论
Azzi Abdelmalek
2014-4-2
Try this
n=size(A,1);
k=1;
while k<n
if any(all(bsxfun(@le,A(k,:),A(k+1:end,:)),2))
A(k,:)=[];
k=k-1;
end
k=k+1;
n=size(A,1);
end
A
更多回答(1 个)
Andrei Bobrov
2014-4-2
编辑:Andrei Bobrov
2014-4-3
blockproc(A,[2,3],@(x)max(x.data))
ADD after Valley's comment
cell2mat(accumarray...
(cumsum([true;diff(A(:,1))~=0]),(1:size(A,1))',[],@(x){max(A(x,:),[],1)}))
other variant
out = A(~any(triu(squeeze(all(bsxfun(@ge,A,reshape(A',1,size(A,2),[])),2)),1)),:)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Calendar 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!