+1

New Channel Type Suggestion : Stack Channel

Nick Pridham 4 years ago in IQANdesign 0

I have a few Qcode situations now where I have a large group of say 1000 variables and I want to find out:

Highest Value

2nd Highest Value

3rd Highest Value


I do have a very long winded solution to this in Qcode but I would love to have a  something more efficient.  

############

One Qcode approach would be some additional array commands such as

ArrayIndexOfMax-1(Array)// 2nd highest number

ArrayIndexOfMax-2(Array)// 3rd highest number

ArrayIndexOfMax-3(Array)// 4th highest number

…...

ArrayIndexOfMin+1(Array)//2nd lowest number

ArrayIndexOfMin+2(Array)//3rd lowest number

ArrayIndexOfMin+3(Array)//4th lowest number

############


This is one approach we have used on other projects

int i=0;

int max_values[3] = {0,0,0};

int array_of_values[1000] = {1,2,45,67,45 ... };

for(i=0;i<1000;i++)

{

//if this item is larger than the largest then save it

if(array_of_values[i] >= max_values[0])

{

//push the largest values down the list as we have a new largest

max_values[2] = max_values[1];

max_values[1] = max_values[0];

//now save newest (as it the largest)

max_values[0] = array_of_values[i];

}

}

printf("The largest Value is %u",max_values[0]);

printf("The Second largest Value is %u",max_values[1]);

printf("The Third largest Value is %u",max_values[2]);


############