Execluding an array member ( equivelent to [] operator in MATLAB )

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hefty1985
    New Member
    • Jul 2007
    • 7

    Execluding an array member ( equivelent to [] operator in MATLAB )

    Hi Guys,

    I am new to this web. I have a fairly simple problem. I have an array of certain double precision numbers. What would be the best way for execluding one of the array members without affecting the other values. For example:

    Input array: [ 0 1 2 7 6 **0** 4 9 8]

    Desired Ouput array is: [ 0 1 2 7 6 4 9 8]

    I know in MATLAB it can be done by [] brackets any idea of a good function that would carry out such functionality.

    Best regards,

    BASHAR
  • ravenspoint
    New Member
    • Jul 2007
    • 111

    #2
    It may be time to upgrade from arrays to STL vectors. If you do so you will gain many things, incuding the method erase which removes a specified element,

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      I agree with ravenspoint.

      However, if you wish to do it the hard way, use a second array as a map:

      Input array: [ 0 1 2 7 6 0 4 9 8]
      Map array: [ 1 1 1 1 1 0 1 1 1]

      Then iterate the map array and only use elements from the input array that are marked in the map.

      Comment

      • ravenspoint
        New Member
        • Jul 2007
        • 111

        #4
        Originally posted by weaknessforcats

        Then iterate the map array and only use elements from the input array that are marked in the map.
        That's a clever solution.

        Use a bit array for the the map, so as not to double your storage requirements.

        If you enjoy fancy footwork, make the map entirely abstract and use simple compression, so that

        [ 1,1,1,0,1,1] becomes [0-2,4-5]

        Comment

        Working...