Thread: matrix

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    8

    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. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    8

    Thanks

    have worked it out now - thanks all!

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    8

    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. #4
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    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.

  5. #5
    Registered User
    Join Date
    Apr 2002
    Posts
    8

    more info

    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. #6
    Something Clever ginoitalo's Avatar
    Join Date
    Dec 2001
    Posts
    187
    What about doing Bubba's solution before you call the function
    and the in the function ?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C - access violation
    By uber in forum C Programming
    Replies: 2
    Last Post: 07-08-2009, 01:30 PM
  2. Matrix Help
    By HelpmeMark in forum C++ Programming
    Replies: 27
    Last Post: 03-06-2008, 05:57 PM
  3. Gauss-Jordan Matrix Inversion in C++
    By Max_Power82 in forum C++ Programming
    Replies: 3
    Last Post: 12-03-2006, 08:31 PM
  4. Matrix and vector operations on computers
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 05-11-2004, 06:36 AM