How to transfer value in a matrix?

1 visualización (últimos 30 días)
yue ishida
yue ishida el 1 de Dic. de 2011
I have create a matrix for a table as below
a=[1 0 0 1 3;2 3 1 7 0;1 1 1 2 3]
Therefore I need to construct the code based on the algorithm below:
1.I need to remove 0 in each row, so the value left in each row do not include zero
2.Every row of matrix will divided into two partition, partition C1 and C2.The row will divided by 2, if the element in a row is odd, with the least no of element will put in C1, and the rest in C2.
3. C2 in each row will change place with C1 in the next row. If the no of elements C2 more than C1, so it will change the first same no of elements C1, the excess element will keep in initial C2 after elements C1 is placed. If the C1 more than C2, the C1 also do the same thing.
4. Operation 3 need to do 3 cycles.
I hope I can get help to solve my problem.

Respuestas (1)

yue ishida
yue ishida el 4 de Dic. de 2011
First the matrix is like this:
1 2 3 0
1 2 4 5
0 9 7 0
1 3 4 6
Next the matrix will become like this:
1 2 3
1 2 4 5
9 7
1 3 4 6
Then, the matrix will become :
1 1 2
2 3 9 5
4 1
7 3 4 6
Finally:
1 1 2 0
2 3 9 5
0 4 1 0
7 3 4 6

Categorías

Más información sobre Genetic Algorithm 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