## Is there a way to use part of arrays in OSCAT functions? document.SUBSCRIPTION_OPTIONS = { "thing": "topic", "subscribed": false, "url": "subscribe", "icon": { "css": "fa fa-envelope-o" } };

leandroct
2019-02-20
2019-02-21
• leandroct - 2019-02-20

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 := 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)

• Anonymous - 2019-02-21

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;