I have a big array where I need to make calculations in parts of it. One of that calculation is a median value. In the OSCAT library there is a median calculation, but it seems only to work if I calculate the median of the whole array. My doubt is::
- Is there a way to run the median funcion in only part of array? (Less than the full array size)
- Is there a way to run the median function starting not in the first position of array?
Here a test program:
(TAB: ARRAY[1..1200] OF REAL;)
TAB: ARRAY[1..9] OF REAL;
TAM: INT := 36;
TAB := 5; TAB := 40; TAB := 25; TAB := 57; TAB := 70; TAB := 34; TAB := 80; TAB := 50; TAB := 95;
//SIZE_TAB := SIZEOF(TAB);
//If TAB size is 1..9, the SIZEOF is 4*9 = 36. Only if I put this value, the instruction works correctly. Then, I ask:
// - Is there a way to run the funcion in only part of array? (Less than the full array size)
// - Is there a way to run the function starting not in the first position TAB of array? (i.e. TAB)
Mediana := OSCAT_BASIC._ARRAY_MEDIAN(ADR(TAB) , TAM);
Originally created by: scott_cunningham
In your example, if you only want to work on the elements 3..9, then you must change the size you pass. The function assumes an entry uses 4 bytes, so if you send it 36, it will calculate you have 9 elements!
For elements 3..9 you would call oacat(ADR(TAB(3)), SIZEOF(REAL)*7)
(Remember 3..9 is actually 7 elements!
I would suggest not hard-coding your array size - use the SIZEOF keyword.
Also, note that the function modifies the array by sorting, so if you send only a partial, only that part will be modified. Be sure this won’t cause any troubles!
In general, something like this:
Start := 3;
End := 6;
pStart := ADR(MyArray(Start));
NmBytes := SIZEOF(REAL)*(End-Start+1);
Ans := ARRAY_MEDIAN(pStart, NmBytes);
Code not tested!!!
Log in to post a comment.