Home > database >  How can i create proportionnel matrix from an existing matrix
How can i create proportionnel matrix from an existing matrix

Time:12-12

Starting matrix: tab[2][3]

Values: 1 0 1 0 1 0

I want to create this matrix (rows and cols are proportionnel to our tab[2][3] by x50): tab[100][150]

Values:

for row 0 to 50:
col 0 to 50 = 1    
col 51 to 100 = 0
col 101 to 150 = 1

for row 51 to 100
col 0 to 50 = 0    
col 51 to 100 = 1
col 101 to 150 = 0

I need help for creating this matrix in c

Thank you

CodePudding user response:

I feel cheap answering this trivial question with a trivial bit of code
(but since 101010 is binary for 42, a tribute to Douglas Adams is not to be ignored.)

int main() {
    int base[2][3] = { { 1, 0, 1, }, { 0, 1, 0 } };
    int big[2*50][3*50};

    for( int r = 0; r < 2 * 50; r   )
        for( int c = 0; c < 3 * 50; c   )
            big[r][c] = base[r/50][c/50];

    return 0;
}

Generalising this (and improving it) is left as an exercise for the reader.

(Here is another recent answer (today) involving DNA (Douglas Noel Adams)
https://stackoverflow.com/a/74765117/17592432
Merry Christmas!)

  •  Tags:  
  • c
  • Related