cancel
Showing results for
Did you mean:

Solved!
Go to solution

## Determine if a channel is monotonic (increasing specifically)

I'm sure I'm doing this horribly wrong, but I don't know really anything about the available functionality, so I'll ask here.

I'd like to know if a given Channel is monotonic.

DIAdem already displays this information in the "Other" information section, under "Monotony". I don't appear to be able to read that value as a property (it's greyed out - perhaps this has some special meaning).

A naive (working) implementation is as follows:

```For Each gr In oAllGroups
isMonotonic(index) = True
Set oCh = gr.Channels("ChannelNameHere")
Dim innerIdx, delta
For innerIdx = 1 To oCh.Size-1
delta = oCh.Values(innerIdx+1) - oCh.Values(innerIdx)
If delta <= 0 Then
isMonotonic(index) = False
End If
Next
Call MsgBoxDisp(isMonotonic(index))
index = index + 1
Next```

but of course this is dreadfully slow (and only checks increasing monotonically - presumably the property also allows decreasing).

Probably use of a Break would speed this up (since I can stop checking once I find a step down).

Is there some built-in function that can accomplish this much more quickly?

The channel isn't evenly spaced, but it should be monotonic (so I expect in general the box to display TRUE, and the check when done in this manner to require ch.Size number of checks...)

Message 1 of 3
(984 Views)
Solution
Accepted by cbutcher

## Re: Determine if a channel is monotonic (increasing specifically)

If you see a property in DIAdem portal, you can drag and drop it into script to get a script line to read it.

`Data.Root.ChannelGroups(1).Channels("Time").Properties("monotony").Value`

The greyed out just means it is not writable.

```dim chO : set chO = data.Root.ChannelGroups(1).Channels(1)
Call ChnCharacter(chO) ' calculate characteristics it
LogFileWrite chO.Properties("monotony").Value```

ChnCharacter or ChnCharacterAll can be used to make sure that the characteristic values are calculated.

Message 2 of 3
(963 Views)

## Re: Determine if a channel is monotonic (increasing specifically)

'Call LogFileWrite("bChnMonotonyIsIncreasing() = " & bChnMonotonyIsIncreasing(Data.Root.ChannelGroups(1).Channels(1)))

Dim oChn
For Each oChn In Data.Root.ChannelGroups(1).Channels
Call LogFileWrite("bChnMonotonyIsIncreasing(" & oChn.Name & ") = " & bChnMonotonyIsIncreasing(Data.Root.ChannelGroups(1).Channels(1)))
Next

Function bChnMonotonyIsIncreasing(ByVal oChn)
'Returns TRUE if the monotonony of oChn is increasing.
bChnMonotonyIsIncreasing = False
If Not IsObject(oChn) Then Call Err.Raise(65535,,"ERROR - object of type channel expected")
Call ChnCharacter(oChn)
If Not oChn.Properties.Exists("monotony") Then Exit Function
If StrComp(oChn.Properties("monotony").Value,"Increasing",vbTextCompare) = 0 Then bChnMonotonyIsIncreasing = True
End Function 'bChnMonotonyIsIncreasing()

Message 3 of 3
(890 Views)