vex array remove specific element

   11182   6   2
User Avatar
Member
28 posts
Joined: Oct. 2013
Offline
I have an array of integers :

“5 0 11 2 7”

how can I remove “11” so I can get the array:

“5 0 2 7”

Thanks!
User Avatar
Member
4534 posts
Joined: Feb. 2012
Online
Create a new array, and add every element in your original array except the element you want to remove.

Unfortunately array functionality is pretty limited. If it was the last element, you could use the pop method.
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | pragmaticvfx.gumroad.com
User Avatar
Member
28 posts
Joined: Oct. 2013
Offline
Thank you for your answer Pusat!

I wish Sesi added some tools in arrays. Softimage ICE is good place to get some ispiration on that subject…
User Avatar
Member
36 posts
Joined: Feb. 2009
Offline
for example:

void removeFromArray(int inputArray; int newArray; int removalItem)
{
//loop through all elements of array
int alength = len(inputArray);
int counter = 0;

for(int i=0; i<alength; i++)
{

//if it doesnt match removalItem add it to newArray
if(inputArray!=removalItem)
{
newArray= inputArray;
counter++;
}
}
}

int a = {1,2,3};
i@bob;

removeFromArray(a, @bob, 3);
User Avatar
Member
4 posts
Joined: June 2016
Offline
how about this?

https://www.sidefx.com/docs/houdini16.0/vex/functions/removeindex [www.sidefx.com]

void removeindex(arraytype &array; const int index)

and kind of how to use it?
User Avatar
Member
2042 posts
Joined: Sept. 2015
Offline
Put the following code in a point wrangle(Detail once only mode) and look at the Geometry spreadsheet with Detail tab selected to see the results.

The first argument is the array you want to remove an element from.
The second argument is the index to the element you want to remove.

If the second argument is positive is starts to count from the left of the array and moves to the right.(Starting the count with 0).
In this case if you uncomment the first function the number ‘3’ will be removed from the array.

If the second argument is negative the counting moves from the right of the array to the left of the array.
However, keep in mind as with the second function whos seconde argument is -2. That the first index of 0 is still the number ‘8’ in the case of this array.

Think of the array as a number line with the first element being indexed as 0 ( in this case that is the number 8).

So if the second argument is positive the counting goes right. If negative the counting goes left. But in this case going left, there is nothing there, so it wraps around and continues conting from the end - continuing going left.

If the second argument - positive or negative, is more than the length of the array - no changes are made to the array.

So if the second function is uncommented (and the first commented out), the number ‘9’ will be removed from the array.

int @My_Array[];

@My_Array = {8,6,3,1,6,5,9,7};

//removeindex(@My_Array, 2);
//removeindex(@My_Array, -2);
User Avatar
Member
18 posts
Joined: Aug. 2018
Offline
int removevalue(<type>&array, <type>value)

Removes the first instance of value found from the array. Returns 1 if an item was removed, or 0 otherwise.
  • Quick Links