<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Is there a way to use part of arrays in OSCAT functions?</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/abc2ba4578/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/abc2ba4578/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/abc2ba4578/</id><updated>2020-02-27T15:08:08.669000Z</updated><subtitle>Recent posts to Is there a way to use part of arrays in OSCAT functions?</subtitle><entry><title>Is there a way to use part of arrays in OSCAT functions?</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/abc2ba4578/?limit=25#06db" rel="alternate"/><published>2020-02-27T15:08:08.669000Z</published><updated>2020-02-27T15:08:08.669000Z</updated><author><name>Anonymous</name><uri>https://forge.codesys.com/u/*anonymous/</uri></author><id>https://forge.codesys.com9b5e45f6158b9fc5c317fadbfa4a8e9ecefa76fe</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;&lt;em&gt;Originally created by:&lt;/em&gt; scott_cunningham&lt;/p&gt;
&lt;p&gt;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!&lt;/p&gt;
&lt;p&gt;For elements 3..9 you would call oacat(ADR(TAB(3)), SIZEOF(REAL)*7)&lt;br/&gt;
(Remember 3..9 is actually 7 elements!&lt;/p&gt;
&lt;p&gt;I would suggest not hard-coding your array size - use the SIZEOF keyword. &lt;/p&gt;
&lt;p&gt;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!&lt;/p&gt;
&lt;p&gt;In general, something like this:&lt;/p&gt;
&lt;p&gt;Start := 3;&lt;br/&gt;
End := 6;&lt;br/&gt;
pStart := ADR(MyArray(Start));&lt;br/&gt;
NmBytes := SIZEOF(REAL)*(End-Start+1);&lt;br/&gt;
Ans := ARRAY_MEDIAN(pStart, NmBytes);&lt;/p&gt;
&lt;p&gt;Code not tested!!!&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Is there a way to use part of arrays in OSCAT functions?</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/abc2ba4578/?limit=25#3080" rel="alternate"/><published>2020-02-27T15:08:08.021000Z</published><updated>2020-02-27T15:08:08.021000Z</updated><author><name>leandroct</name><uri>https://forge.codesys.com/u/leandroct/</uri></author><id>https://forge.codesys.combe5181633c0fc99689d0207148976807b66f063b</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;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::&lt;br/&gt;
- Is there a way to run the median funcion in only part of array? (Less than the full array size)&lt;br/&gt;
- Is there a way to run the median function starting not in the first position of array?&lt;/p&gt;
&lt;p&gt;Thanks!&lt;/p&gt;
&lt;hr/&gt;
&lt;p&gt;Here a test program:&lt;/p&gt;
&lt;hr/&gt;
&lt;p&gt;VAR&lt;br/&gt;
        (&lt;em&gt;TAB: ARRAY&lt;span&gt;&lt;span&gt;[1..1200]&lt;/span&gt;&lt;/span&gt; OF REAL;&lt;/em&gt;)&lt;br/&gt;
    TAB: ARRAY&lt;span&gt;[1..9]&lt;/span&gt; OF REAL;&lt;br/&gt;
    Mediana: REAL;&lt;br/&gt;
    TAM: INT := 36;&lt;br/&gt;
    SIZE_TAB: UINT;&lt;br/&gt;
END_VAR&lt;/p&gt;
&lt;p&gt;TAB&lt;span&gt;[1]&lt;/span&gt; := 5; TAB&lt;span&gt;[2]&lt;/span&gt; := 40; TAB&lt;span&gt;[3]&lt;/span&gt; := 25; TAB&lt;span&gt;[4]&lt;/span&gt; := 57; TAB&lt;span&gt;[5]&lt;/span&gt; := 70; TAB&lt;span&gt;[6]&lt;/span&gt; := 34; TAB&lt;span&gt;[7]&lt;/span&gt; := 80; TAB&lt;span&gt;[8]&lt;/span&gt; := 50; TAB&lt;span&gt;[9]&lt;/span&gt; := 95;&lt;/p&gt;
&lt;p&gt;//SIZE_TAB := SIZEOF(TAB);&lt;br/&gt;
//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:&lt;br/&gt;
// - Is there a way to run the funcion in only part of array? (Less than the full array size)&lt;br/&gt;
// - Is there a way to run the function starting not in the first position TAB&lt;span&gt;[1]&lt;/span&gt; of array? (i.e. TAB&lt;span&gt;[3]&lt;/span&gt;)&lt;/p&gt;
&lt;p&gt;Mediana := OSCAT_BASIC._ARRAY_MEDIAN(ADR(TAB) , TAM);&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>