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 & HelpSyntax Questions › comparing elements in an array
Page Index Toggle Pages: 1
comparing elements in an array (Read 340 times)
comparing elements in an array
Aug 1st, 2009, 10:53am
 
Hi,

I am trying to compare all the elements in a float array to each other.
I  would like to know whether any of the numbers are the same or within a range of each other, amend the particular numbers ( make the higher value larger and the lower value smaller) and then put them back into an array of the same length as my initial array and at the same position they were in that initial array. I am not really sure how to go about doing it, e.g.  what structure I should follow, how do i make sure that changing the values doesn't effect the 'being in range' for values that were previously fine. Any help is appreciated. Thanks

My code so far doesn't really do its just a very simple start:

float[] xPosCount = { 100.5 , 30.5 , 65.5 , 20.5 ,130.5 };


for (int m = 0 ; m < xPosCount.length; m++)          
         {                                          
          for (int n = 0; n < xPosCount.length; n++)
               {
               if(m!=n)
               {
                   if (((xPosCount[n]) >= (xPosCount[ m]+30))  || ((xPosCount[n])  <=  (xPosCount[ m]-30) ))
                   {
                      println("position is fine: " + xPosCount[m]);                      
                   }
                   
                    else if (((xPosCount[n]) <= (xPosCount[ m]+30))  || ((xPosCount[n])  >=  (xPosCount[ m]-30) ))
                   {
                     float XposAmend = (xPosCount[m] - 15);
                      float XposAmendsecond = (xPosCount[m+1] + 15);
                     println("we are to close ");
                      println("XposAmend: " +XposAmend);
                     println("XposAmendsecond: " +XposAmendsecond);
                 }
               }
            }
         }



Page Index Toggle Pages: 1