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?
Thanks!
Here a test program:
VAR
(TAB: ARRAY[1..1200] OF REAL;)
TAB: ARRAY[1..9] OF REAL;
Mediana: REAL;
TAM: INT := 36;
SIZE_TAB: UINT;
END_VAR
//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[1] of array? (i.e. TAB[3])
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous

20190221
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 hardcoding 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)*(EndStart+1);
Ans := ARRAY_MEDIAN(pStart, NmBytes);
Code not tested!!!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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?
Thanks!
Here a test program:
VAR
(TAB: ARRAY[1..1200] OF REAL;)
TAB: ARRAY[1..9] OF REAL;
Mediana: REAL;
TAM: INT := 36;
SIZE_TAB: UINT;
END_VAR
TAB[1] := 5; TAB[2] := 40; TAB[3] := 25; TAB[4] := 57; TAB[5] := 70; TAB[6] := 34; TAB[7] := 80; TAB[8] := 50; TAB[9] := 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[1] of array? (i.e. TAB[3])
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 hardcoding 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)*(EndStart+1);
Ans := ARRAY_MEDIAN(pStart, NmBytes);
Code not tested!!!