We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Array Question
Page Index Toggle Pages: 1
Array Question? (Read 400 times)
Array Question?
Dec 3rd, 2007, 11:41pm
 
I'm having the following problems.  

How do you delete the nth element from an array?  Suppose I had an array of floats that contained 10 values, and I wanted to delete the 7th element.  How do i go about "popping" it off, and having the array shrink to 9 elements, while maintaining the same order?
Re: Array Question?
Reply #1 - Dec 4th, 2007, 4:10am
 
try this:

void setup(){
 float[] f = {
   .2, .3 , .5, .03, .1, .99, .45, .345, .0234, .51};
 println(remove(f, 6));
}

float[] remove(float[] vals, int index){
 vals = concat(subset(vals, 0, index), subset(vals, index+1));
 return vals;
}
Page Index Toggle Pages: 1