#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    57
    Rep Power
    0

    Invalid types 'double*[double]' for array subscript


    Hi people I have the error I named the question in the function: (With "here" I comment where the compiler send me the error):

    Code:
    oid ftshifting(matriz filter,int rows,int cols){
    
      double r2,c2,tmp1_3,tmp2_4;
    
      r2 = (rows+1)/2;
      c2 = (cols+1)/2;
    
      for (int i = 0; i<rows/2; i++){
         for (int k = 0; k<cols/2; k++){
    
              tmp1_3 = filter[i][k];
              filter[i][k] = filter[i+r2][k+c2]; //error
              filter[i+r2][k+c2] = tmp1_3;    //error
    
              tmp2_4 = filter[i+r2][k];         //error
              filter[i+r2][k] = filter[i][k+c2]; //error
              filter[i][k+c2] = tmp2_4;        //error
         }
      }
    }
    
    double **createmat(int rows,int cols){
    
        double **m;
    
        m=new double*[rows];
         for(int i=0;i<rows;i++)
             m[i]=new double[cols];
    
        return m;
    }
    The strange thing is that it worked before inserting the typedef double**matriz;
    I tested the function and it worked. Also, other function use this data and it works normally, example: (no errors at compiler time)

    Code:
    void pre_filter_Computations(matriz radius,matriz theta,int cols,int rows){
    
      double X[rows][cols],Y[rows][cols];
      double x[cols],y[rows];
      double epsilon = 0.0001;
    
      for(int i=0;i<cols;i++){
          x[i]=((double)(i-cols)/2)/((double)cols/2);
      }
    
    
      for(int z=0;z<rows;z++){
           y[z]=-(((double)(z-rows)/2)/((double)rows/2));
       }
    
     for(int m=0;m<cols;m++){
      for(int n=0;n<rows;n++){
           X[m][n]=x[m];
           Y[m][n]=y[n];
      }
     }
    
          for(int a=0;a<rows;a++){
                for(int b=0;b<cols;b++){
    
                     X[a][b] = pow(X[a][b],2);
                     Y[a][b] = pow(Y[a][b],2);
                     X[a][b] = X[a][b] + Y[a][b];
                      radius[a][b] = sqrt(X[a][b]);
               }
           }
          radius[rows/2][cols/2]=1;
    
          for(int a=0;a<rows;a++){
               for(int b=0;b<cols;b++){
                   radius [a][b]= radius[a][b] + epsilon;
                   theta[a][b] = atan2(Y[a][b],X[a][b])*180/PI;
               }
          }
    }
    Last edited by residentelvio; July 1st, 2013 at 10:09 AM.
  2. #2
  3. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,091
    Rep Power
    2222
    filter[i][k] = filter[i+r2][k+c2];

    Array subscripts must be int expressions. r2 and c2 are declared as doubles. Hence, i+r2 and k+c2 are double expressions. You cannot use a double expression as an array subscript

    You would have to convert those double expressions to int expressions; eg, by casting them as int to either truncate or round the value ( just using (int) truncates, so to round you add 0.5 before casting to int).
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    57
    Rep Power
    0
    You have the reason. I just chanhed the temporals value from int to float and I forget to chang matrix index to int. Howewer in r2 & c2 I put rows+1 to don t have problems with the division and to obtain the index I need. But thanks a lot to help
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    57
    Rep Power
    0

    Error in a line


    Hi people. I have en error translating a function from Matlab to C/C++ :

    Code:
    radius(floor(rows/2+1),floor(cols/2+1)) = 1;
     % Get rid of the 0 radius value at the 0
     % frequency point (now at top-left corner)
     % so that taking the log of the radius will 
     % not cause trouble.
    What I did is:

    Code:
    radius[rows/2][cols/2]=1;
    I m sure it s there the problem, because before this line I can print what I want and I can see it at run-time, but after this line I can not print nothing and the work is like blocked. Do you know the error?
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    40
    Rep Power
    18
    std::vector:: operator[]

    reference operator[] (size_type n);
    const_reference operator[] (size_type n) const;



    radius(floor(rows/2+1),floor(cols/2+1)) = 1;
    ==>
    Code:
    radius[(size_type)floor(rows/2+1)][(size_type)floor(cols/2+1)] = 1;
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    57
    Rep Power
    0
    I did:

    Code:
    radius[(int)floor(rows/2+1)][(int)floor(cols/2+1)]=1;
    Used int because to access an element I have to use just int numbers.
    But I have the same problems.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    57
    Rep Power
    0
    I found the error that was in the meshgrid. I mean:

    Code:
    for(int m=0;m<cols;m++){
      for(int n=0;n<rows;n++){
           X[m][n]=x[m];
           Y[m][n]=y[n];
      }
    }
    Meshgrid :
    Code:
    [X,Y] = meshgrid(x,y) transforms the domain specified by vectors x and y into arrays X and Y, which can be used to evaluate functions of two variables and three-dimensional mesh/surface plots. The rows of the output array X are copies of the vector x; columns of the output array Y are copies of the vector y.
    I had to use x vector for cols and y for rows as my teacher said me, I inverted in the innested for rows and cols, so causing a multiply of rows and cols. Now I d like to know if the meshgrid works well. Do you think is right?
    Code:
     
    for(int m=0;m<rows;m++){
      for(int n=0;n<cols;n++){
           X[m][n]=x[m];
           Y[m][n]=y[n];
      }
    }
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    40
    Rep Power
    18
    ????? W H Y ?????
    Too many threats for a simple problem.

    Meshgrid from Matlab to C/c++
    http://forums.devshed.com/c-programming-42/meshgrid-from-matlab-to-c-c-947561.html

    Pointer to a vector of vectors
    http://forums.devshed.com/c-programming-42/pointer-to-a-vector-of-vectors-947787.html

    Glibc error
    http://forums.devshed.com/c-programming-42/glibc-error-947793.html

    Error in a line
    http://forums.devshed.com/c-programming-42/error-in-a-line-947837.html

    Invalid types 'double*[double]' for array subscript
    http://forums.devshed.com/c-programming-42/invalid-types-double-double-for-array-subscript-947829.html

    Error going in a function
    http://forums.devshed.com/c-programming-42/error-going-in-a-function-947870.html

    ????? W H Y ?????

    ------------------------

    Comment on your code

    1. Why do you create so many variables for loop indexing?
    Using int i and j might enough for all works.

    2. Why this spaghetti?
    Code:
    X[a][b] = pow(X[a][b],2);
    Y[a][b] = pow(Y[a][b],2);     
     X[a][b] = X[a][b] + Y[a][b];  // <==> Xi = Xi^2 + Yi^2
    radius[a][b] = sqrt(X[a][b]);
    ...
    
    theta[a][b] = atan2(Y[a][b],X[a][b])*180/PI; //<==> theta = arctan (Yi^2 / (Xi^2 + Yi^2))
    Is that what you expect?

    Mathematically: theta = arctan (delta Y / delta X)

    3.
    Code:
    for(int m=0;m<rows;m++){
      for(int n=0;n<cols;n++){
           X[m][n]=x[m];
           Y[m][n]=y[n];
      }
    }
    is not correct.

    x[i] iterating through cols, y[i] through rows.
    Must be...
    Code:
    for(int m=0;m<rows;m++){
      for(int n=0;n<cols;n++){
           X[m][n]=x[n]; //change with cols
           Y[m][n]=y[m]; //change with rows
      }
    }

    4. X-matrice has size of 534*696*8 = 2,973,312 bytes
    X and Y eat memory 5.67 MB.

    Why do you think this way? Why not calculate on the fly?

    :confused:

    Comments on this post

    • salem agrees : Not to mention all the duplicates of those threads on other forums as well

IMN logo majestic logo threadwatch logo seochat tools logo