How to transfer value in a matrix?

조회 수: 1 (최근 30일)
yue ishida
yue ishida 2011년 12월 1일
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.

답변 (1개)

yue ishida
yue ishida 2011년 12월 4일
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

카테고리

Help CenterFile Exchange에서 Genetic Algorithm에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by