Good day.

I have a problem with matrices / arrays, i cannot resolve. I have no idea how to start...

I have two 2D matrices and i want to overlap (mix?) one over the other, no matter what dimensions they have.

For example :

a = [ (1,2,3,4,5),
(9,7),
(0,0,0,0,0),
(5,5,5) ]

b = [ (0,0,0),
(1,1,1,1),
(2,2,2,2) ]

Now, if i want to put a over b, i get the result:

a over b = [
(1,2,3,4,5),
(9,7,1,1),
(0,0,0,0,0),
(5,5,5,2) ]

And b over a = [
(0,0,0,4,5),
(1,1,1,1),
(0,0,0,0,0),
(2,2,2,2) ]

I think this operation has a name in mathematics, but i don't know how to call it... and what to search for.
I tried 2 days to make a good algorithm and i gave up... Please keep in mind that my matrices are not square or rectangle. They can be very nasty to combine.
In fact, there is an undefined number of matrices i need to overlap, all this overlaping is in a strict order. I suppose that if i have the algorithm for 2 matrices, i can make a big "for" cicle and mix the next matrix over the previous result.
I need this overlap to happen AS FAST AS POSSIBLE. I need to overlap matrices with milions of elements, like 1600x1200.

Any help is welcome. Thank you very much.

Member Avatar for jencas

Maybe using a vecor of vectors instead of a two-dimensional array helps solving your problem

well at first place ur problem is not a 2d matrix .infact its multi dimensional ..

the following algo might help u a bit.

1. u will have to accept the rows and coloumns and dynamicallyy create an array.for both of yours a n b matrix.

2. as you will have to overlap a over b.
check whether the all matrix positions in a are in b . if they arent make an account of it and dont execute the underneath step.

3. then over write the contents of b from a thats it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.