Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.

### Computing mode with uncertain data output.

Makada Jan 4, 2022 05:35 PM

Hi,

I was wondering if i can use part of this code to calculate the most frequently occuring data, but not knowing what the data output is?

Or another wat to accomplish that?

So lets say i want to know the most frequently ocurring data samples from a windsensor (in m/s) from 60 one second samples.

```'WS600Msmt is the variable that holds the result from the sensor
Public WS600Msmt
Public Mode(4)
Public DestMaxSpa(2)
Public WS600Mode

'count the occurrences of each mode and put the counts into
'an array
If WS600Msmt = 0 then Mode(1) = Mode(1) + 1
If WS600Msmt = 40 then Mode(2) = Mode(2) + 1
If WS600Msmt = 60 then Mode(3) = Mode(3) + 1
If WS600Msmt = 70 then Mode(4) = Mode(4) + 1

'use MaxSpa to find the maximum of the Mode array
'the second destination variable is the Location
'within the array where the Max occurs
MaxSpa (DestMaxSpa, 4, Mode(1))

'Return a mode, based on which index in Mode() holds the max
If DestMaxSpa(2)= 1 Then WS600Mode = 0
If DestMaxSpa(2)= 2 Then WS600Mode = 40
If DestMaxSpa(2)= 3 Then WS600Mode = 60
If DestMaxSpa(2)= 4 Then WS600Mode = 70```

JDavis Jan 6, 2022 04:37 PM

Look at the Histogram instruction.

Makada Jan 6, 2022 05:58 PM

Hi JDavis,

Ive looked at the histogram function some time ago, and found out it is a bit beyond my capabillities crbasic wise:(

But i will try it again:)

With the kindest regards,

Mark

Makada Jan 6, 2022 07:52 PM

Hi,

I found this example from the crbasic help.

Am i right in thinking that when i replace the 'public Tblock' with my precipitation type 'public Precipitation'  code and change the LoLim and UpLim , it will woŕk ok?

With the kindest regards,

Mark

```Public Tblock(2),BattV, PTemp

DataTable( ACCEL, 1, 10000 )    'Trigger, buffer of ,10000 Records

DataInterval( 0, 1, Sec, 100 ) 'Synchronous, 100 lapses

'-------------------- Thermocouple Blocks --------------------

Sample ( 1, Tblock(), FP2 )   'Reps,Source,Type

'Histogram (src,type,disable,numbins,form,1,lolim,hilim)

Histogram( Tblock(), FP2, 0, 2, 001, 100,10,30)

EndTable

BeginProg

Scan (1,Sec,3,0)

Battery (BattV)

PanelTemp (PTemp,60)

TCDiff (Tblock(),2,mV200C,1,TypeT,PTemp,True ,0,60,1.0,0)

CallTable ACCEL

NextScan

EndProg
```

Makada Jan 6, 2022 09:43 PM

I believe ive got it working so far.

10 = rain

20 = snow

30 = sleet

40 = freezing rain

50 = hail

Ive set the LoLim to -5 and the UpLim to 55 with 6 bins.

But when the precipitation type is 10, it is visible in the hst(2) field instead of hst(1)...

With the kindest regards,

Mark

Makada Jan 19, 2022 07:54 AM

The histogram is working fine now:)

``` DataTable( Histogram_Precip, 1, 10000 )    'Trigger, buffer of ,10000 Records
DataInterval( 0, 1,Sec, 100 ) 'Synchronous, 100 lapses
Sample ( 1, Precepitation_type(), FP2 )   'Reps,Source,Type
Histogram( Precepitation_type(),IEEE4, 0, 5,001,Precepitation_type(),0,55.5)
EndTable
```

The next step is  how to correct data, when my precipitation type sensor sees insects as precipitation.

With the kindest regards.