How to filter the rows i donot want in a matrix

4 visualizaciones (últimos 30 días)
valley
valley el 2 de Abr. de 2014
Editada: Azzi Abdelmalek el 3 de Abr. de 2014
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 comentarios
Azzi Abdelmalek
Azzi Abdelmalek el 2 de Abr. de 2014
Ok, have you tested my edited answer?
valley
valley el 2 de Abr. de 2014
Editada: valley el 2 de Abr. de 2014
i did, to this given example, it is ok, but to more complecated cases, such as a big matrix(600*10), it is not successful. m i correct, ur code didnot compare all the rest rows, just check the first row which matches the condition, to the other possible rows urs didnot consider?
sorry to trouble u again, still this problem, with 2 loops will cost much runtime, is there any other efficient way to solve my problem? if u have any idea about that pl tell me, thank u very much.

Iniciar sesión para comentar.

Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 2 de Abr. de 2014
Editada: Azzi Abdelmalek el 3 de Abr. de 2014
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 comentarios
Azzi Abdelmalek
Azzi Abdelmalek el 2 de Abr. de 2014
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
valley
valley el 3 de Abr. de 2014
thank u so much, it is ok now.

Iniciar sesión para comentar.

Más respuestas (1)

Andrei Bobrov
Andrei Bobrov el 2 de Abr. de 2014
Editada: Andrei Bobrov el 3 de Abr. de 2014
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)),:)
  1 comentario
valley
valley el 2 de Abr. de 2014
thx and sorry 4 the late reply, i've fixed my problem wit 2 loops, but urs seems more efficient, i will try later. thank u

Iniciar sesión para comentar.

Categorías

Más información sobre Calendar en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by