Remove two lowest values and two highest values from array with MLQ4

 

How can I remove the two lowest and the two highest values from an array?  The problem with the code below is that 0 gets removed twice instead of the real second lowest value.

 double x[15];
 x[0]=9;
 x[1]=100;
 x[2]=9;
 x[3]=200;
 x[4]=9;
 x[5]=9;
 x[6]=9;
 x[7]=9;
 x[8]=9;
 x[9]=9;
 x[10]=1;
 x[11]=9;
 x[12]=2;
 x[13]=9;
 x[14]=9;
 x[15]=9;

 x[ArrayMinimum(x)] = 0;
 x[ArrayMinimum(x)] = 0;
 x[ArrayMaximum(x)] = 0;
 x[ArrayMaximum(x)] = 0;

 double ArraySum;
 for(int ArrayIndex = 14; ArrayIndex >= 0; ArrayIndex--) ArraySum += x[ArrayIndex];

 Alert("The average value of x after the two lowest values and the two highest values have been dropped is: ", ArraySum/11);

 

 
hknight:

How can I remove the two lowest and the two highest values from an array?  The problem with the code below is that 0 gets removed twice instead of the real second lowest value.

Did you mean remove ?  or did you mean replace ?  what you are doing is replacing.  When you replace the minimum value with 0 it is still likely to be the minimum. Instead replace the two minimums with  x[ArrayMaximum(x)] + 1  and then replace the 4 maximums.  If you mean remove then that is a more complex task. 
 

ArraySort  will help you one way

 double y[11];   will help you further

 

Clever, thanks for the idea.  This does what I need:

 x[ArrayMinimum(x)] = 999999;
 x[ArrayMinimum(x)] = 999999;
 x[ArrayMaximum(x)] = 0;
 x[ArrayMaximum(x)] = 0;
 x[ArrayMaximum(x)] = 0;
 x[ArrayMaximum(x)] = 0;
 
hknight:

How can I remove the two lowest and the two highest values from an array?  The problem with the code below is that 0 gets removed twice instead of the real second lowest value.

What about something like this:

double x[15] = {9, 100, 9, 200, 9, 9, 9, 9, 9, 9, 1, 9, 2, 9, 9};
ArraySort(x);
ArrayResize(x, ArraySize(x) - 2);
ArraySort(x, WHOLE_ARRAY, 0, MODE_DESCEND);
ArrayResize(x, ArraySize(x) - 2);
// check to see if the result is correct
for (int i = 0; i <= ArraySize(x) - 1; i++) {
   Print ("i: ", i, " and v: ", x[i]);
}

Or, you can try using a combination of ArraySort() and ArrayCopy():

double x[15] = {9, 100, 9, 200, 9, 9, 9, 9, 9, 9, 1, 9, 2, 9, 9};
double y[];
ArraySort(x);
ArrayCopy(y, x, 0, 2, ArraySize(x) - 4);
// verify correct results
for (int i = 0; i <= ArraySize(y) - 1; i++)
   Print ("i: ", i, " and v: ", y[i]);
 
Thirteen, thanks for your ideas.  That does seem like the proper way to do this.
Reason: