Menu

Array multidimensions

2008-07-03
2012-09-15
  • BALLIHI Lahoucine

    Hello everyone
    I just started, coding by IT + +, and I want if it's possible to do this in IT++
    for i=1:10
    Mat3d(:,:,i) = Mat2D;
    end
    thank you for your help

     
    • Stephan Ludwig

      Stephan Ludwig - 2008-07-07

      Hi BALLIHI,

      you are not providing too much details on your problem... I will guess some parameters of yours: You want to construct an equivalent to a 3D array with complex elements. Furthermore you would like to assign a 2D matrix to the array in distinct position.

      You can do this by using the array<mat> class. You find very good information about this in the getting started guide:
      http://itpp.sourceforge.net/current/users_guide.html#array_class

      A code snippet:
      Array<mat> my_3D_array(length); // length corresponds to the max of yout counting variable i, i.e. 10
      mat my_2D_matrix(size_m, size_n); // size_m/n are obviously the dimensions of the 2D matrix

      // assume having calculated with (especially initialised) the 2D matrix
      // Then you can assign this matrix to the array according to your example
      for (int i = 0; i < 10; i++){
      my_3D_array(i) = my_2D_matrix;
      }

      That's it. Hope this helps.

      BTW: This forum is on open discussions, but you are asking for help. You might receive more answers next time by posting to the help forum :-)

      Regards,
      donludovico.

       
    • Darlan Moreira

      Darlan Moreira - 2009-06-25

      I have the same problem.

      The drawback of using Array<mat> is that you cannot do something like
      Mat3d(:,i,:) = Mat2D
      if you need to.

      For that I think that you would need some kind of "three dimensional container", instead of a "one dimensional container" where each element is a "two dimensional container".

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.