Filling matrices: is there a missing or extra character I can't see?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • buckkitty
    New Member
    • Mar 2010
    • 2

    Filling matrices: is there a missing or extra character I can't see?

    Hello,

    Does anyone understand why Data2 would not equal Data? I print, and can see, that they LOOK the same, i.e. have the same number of rows and columns with the same values in each element. But when I pass the matrices to a calc function, they give different results. I am guessing that there is a missing (or extra) character, space, line somewhere that I can't "see".

    The only difference is the way that I fill Data1 and Data2. data_options actually contains 660 elements and Data2 would contain 649. Am I filling Data2 incorrectly? In the end, I want Data2 to be the same as Data1. Here are snippets of my C code...

    double **data1;
    double **data2;
    double *data_options;
    int numobs = 59;
    int Dim1 = 11;

    data1 = matrix(numobs,D im1);
    for (n=0; n<numobs; n++)
    {
    for (k=0; k<Dim1; k++)
    {
    data1[n][k]=data_options[n*Dim1+k];
    }
    }


    data2 = matrix(numobs, Dim1);
    for (n = 0; n<numobs; n++)
    {
    for (k=0; k<Dim1; k++)
    {
    data2[n][k] = data1[n][k];
    }

    }

    thank you!
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    Is it possible that the error is in the calc function? Perhaps there is a variable that is not reinitialized when you run it a second time.
    If you can, try running calc on the same matrix twice and see if you get the same results.
    Last edited by jkmyoung; Apr 15 '10, 02:36 PM. Reason: Removed quote

    Comment

    • buckkitty
      New Member
      • Mar 2010
      • 2

      #3
      When I re-run the calc with same matrix, the values stay the same. So I think everything is being initialized properly. Why do you suppose that the first matrix, Data1, would be filled with "[n*Dim1+k]", which would be "k" more characters than Data2 gets?

      (to me, logically, it should only get "n*Dim1")

      Comment

      Working...