looking condition in matrix

5 visualizaciones (últimos 30 días)
Nejc
Nejc el 10 de Abr. de 2013
Hey,
I got matrix
[ 2 9841 5 4 2 1;
3 79463 1 3 1 0;
3 79463 4 3 1 0;
3 79463 5 3 1 0;
3 79463 1 3 2 0;
3 79463 4 3 2 0;
3 79463 5 3 2 0;
3 79463 1 4 1 0;
3 79463 4 4 1 0;
3 79463 5 4 1 0;
3 79463 1 4 2 0;
3 79463 4 4 2 0;
3 79463 5 4 2 0;
3 79463 1 4 1 1;
3 79463 4 4 1 1;
3 79463 5 4 1 1;
3 79463 4 4 1 1;
3 79463 5 4 1 1;
3 79212 1 3 1 0;]
I have to look for every row in column 1,2,4,5, if they match, then i check last column 6th, where is information if row data is correct or wrong.
If there are both correct and wrong data for rows that all include same values in column 1,2,4,5 than i must keep only correct data and erase wrong. If there is only wrong data for row than i keeep it.
The result should erase those two rows...
3 79463 4 4 1 0;
3 79463 5 4 1 0;
Thank you for your suggestions and solutions, take care.
Nejc
  4 comentarios
Yao Li
Yao Li el 10 de Abr. de 2013
Sorry, I haven't got it yet. Maybe you can take the first 5 rows for example. Pls. give the results for the first 5 rows.
Nejc
Nejc el 10 de Abr. de 2013
No problem, first 5 rows: 2 9841 5 4 2 1; this row is only one which got same 1st,2nd,4th,5th parameters, we look for 6th and it's 1, ok we keep that row...
now next 3 rows have same 1st,2nd,4th,5th parameters, again we check for 6th column and each row have value 0...becasue we dont have 1 in that 6th, we keep that 3 rows.
The crucial here are rows which consist of 1st-3 2nd- 79463 4th-4 5th-1 parameters....We have 8 rows that meet those parameters. So we look 6 column now and there are both 0-wrong and 1- correct, because there are both options i want to keep just correct rows and erase wrong.

Iniciar sesión para comentar.

Respuestas (1)

Andrei Bobrov
Andrei Bobrov el 10 de Abr. de 2013
Editada: Andrei Bobrov el 10 de Abr. de 2013
a = [ 2 9841 5 4 2 1;3 79463 1 3 1 0;3 79463 4 3 1 0;3 79463 5 3 1 0;3 79463 1 3 2 0;3 79463 4 3 2 0;3 79463 5 3 2 0;3 79463 1 4 1 0;3 79463 4 4 1 0;3 79463 5 4 1 0;3 79463 1 4 2 0;3 79463 4 4 2 0;3 79463 5 4 2 0;3 79463 1 4 1 1;3 79463 4 4 1 1;3 79463 5 4 1 1;3 79463 4 4 1 1;3 79463 5 4 1 1;3 79212 1 3 1 0;];
[~,~,ii] = unique(a(:,[1 2 4 5]),'rows');
i1 = histc(ii,1:max(ii));
out = a(ismember(ii,find(i1 > 1)) & a(:,end) == 1,:);
  1 comentario
Nejc
Nejc el 10 de Abr. de 2013
[ 2 9841 5 4 2 1;
3 79463 1 3 1 0;
3 79463 4 3 1 0;
3 79463 5 3 1 0;
3 79463 1 3 2 0;
3 79463 4 3 2 0;
3 79463 5 3 2 0;
3 79463 1 4 2 0;
3 79463 4 4 2 0;
3 79463 5 4 2 0;
3 79463 1 4 1 1;
3 79463 4 4 1 1;
3 79463 5 4 1 1;
3 79463 4 4 1 1;
3 79463 5 4 1 1;
3 79212 1 3 1 0;]
without
3 79463 1 4 1 0;
3 79463 4 4 1 0;
3 79463 5 4 1 0;
but i appreciate your effort.

Iniciar sesión para comentar.

Categorías

Más información sobre Text Data Preparation en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by