1. ## matrix

hi,

I have written functions that add rows and columns (separately) to a matrix. Any existing data is retained. However, when I use both these functions in another function that grows the matrix to the size given by the parameters I am having a problem. The size of the new array is correct but I am not saving the existing data and don't know how to do this. Since I am using existing functions that already copy the old data I assumed that when I called the addrow or addcol function that the data would be copied at this time- but it isn't. Do I need to copy the existing data before I call either of the other functions (if, so how?) or is there another way of doing this? I am a real beginner, so answers in english (possibly with examples) would be very much appreciated.

Thanks

2. ## Thanks

have worked it out now - thanks all!

3. ## Still need help!!!

I have not worked this problem out, I have worked out another problem but posted my thank-yous in the wrong place - please help with matrix problem!!!

4. Well to save the current matrix you could simply do a memcpy to a temp matrix. The size of the matrix would be this:

((rows-1)*width)*(datawidth)

memcpy(sourcematrix,targetmatrix,length)

or you could do it the slow way in C with one for loop (second loop unwound) or with two fors which is slower. Memcpy is the best way to do it.

I have not used memcpy before so I don't know how to go about it.

In my addrow function I did something like this...

Array<BType, IType2>* *oldData = Data;
// reference to the current data
Data = new Array<BType, IType2>*[newRows];
// allocate new Data memory of length newRows

I thought that this would be performed when the addrow function was called and that the original data would be saved at this point - am I way off track!! Is there a similar way to write something that will save the previous matrix before the functions are called?

6. What about doing Bubba's solution before you call the function
and the in the function ?