Divide group into subgroups

I have a matrix 5x5 and i managed from this matrix to create a matrix 5x10 by creating a subgroup of 2 in each column.
So Matrix =
0 0 0 1 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0
0 0 0 0 0 1 0 0 0 0
0 0 0 0 0 0 0 0 0 1
I want to tell that row 1 belongs to group 2, row 2 belongs to group 1, row 3 belongs to group 2, row 4 belongs to group 3 and row 5 belongs to group 5!
Thank you so much

 Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 7 de Abr. de 2016
Editada: Azzi Abdelmalek el 7 de Abr. de 2016

0 votos

group=[2 1 2 3 5]
the variable group indicate what you want

5 comentarios

N.
N. el 7 de Abr. de 2016
I don't have a variable called group! I want to create this vector
Walter Roberson
Walter Roberson el 7 de Abr. de 2016
group=[2 1 2 3 5] is an assignment statement, in which you define that the first entry is group 2, the second is group 1, and so on. You would create that variable using whatever information allowed you to tell us that those were the group numbers when you described the problem.
N.
N. el 7 de Abr. de 2016
Editada: N. el 7 de Abr. de 2016
The group thing is the information that i want to get, its not a thing that i would define.
Azzi Abdelmalek
Azzi Abdelmalek el 7 de Abr. de 2016
Ok, then based on what you can tell one row or another belong to any group?
Maybe this is what you want
A=[0 0 0 1 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0
0 0 0 0 0 1 0 0 0 0
0 0 0 0 0 0 0 0 0 1]
n=size(A,1);
a=any(reshape(A,n,2,[]),2)
b=a(:,:);
for k=1:n
group(k)=find(b(k,:),1)
end

Iniciar sesión para comentar.

Más respuestas (1)

Walter Roberson
Walter Roberson el 7 de Abr. de 2016

0 votos

group = sum( Matrix(1:2:end) | Matrix(2:2:end) .* repmat( 1:size(Matrix,2)/2, size(Matrix,1), 1), 2);
Note: this may give unexpected answers if you have multiple 1's in the same row.

Categorías

Más información sobre Mathematics en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

N.
el 7 de Abr. de 2016

Comentada:

el 7 de Abr. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by