12-07-2012 01:52 PM
I have a channel in DIAdem with a large amount of values (36,000,000) the values contain about 13 decimal places.
I would like to round the value off to about 4 or 5 decimal places max.
Can someone help me figure out how to do this in DIAdem.
Example:
0.3784729837492 ->0.37847
I want do do this for every value in the channel.
can someone help me figure out how to do this?
Thanks in advance,
Tom
Solved! Go to Solution.
12-10-2012 01:37 PM
Hi Tom,
You can utilize the VBScript function, Round(value, number of decimal places). I wrote a quick script in DIAdem which performs this operation on a numeric channel, named dataChannel, and transfers the truncated values a new channel, named truncChannel.
Dim toBeTrunc, i
For i = 1 To Data.Root.ChannelGroups(1).Channels("dataChannel").Properties("length").Value
toBeTrunc = Data.Root.ChannelGroups(1).Channels("dataChannel").Values(i)
Data.Root.ChannelGroups(1).Channels("truncChannel").Values(i) = Round(toBeTrunc,3)
Next
I hope this helps.
Warm Regards,
12-10-2012 06:28 PM
D-cubed's method will work, but with 36,000,000 data points, it will take a long time. Use the calculator. Copy this function into the calculator under analysis, and it will occur just about instantaneously. Replace the 3 with the desired number of decimal places.
Ch("[1]/Channel")=Round(Ch("[1]/ChannelToBeRounded"),3)
If you need a VB Script:
Dim ChannelToRound, DecimalPoints ChanneltoRound="[1]/ChannelToBeRounded" 'Put the channel you want to round here DecimalPoints=6 'Specify the number of decimal points 'This will create a new channel called "Channel" in group 1 with the rounded values Call Calculate("Ch(""[1]/Channel"")=Round(Ch(""" & ChannelToRound & """)," & DecimalPoints & ")",NULL,NULL,"") '... CalculateFormula,CalculateSymbols,CalculateValues,CalculateTargetUnit
12-11-2012 10:39 AM
Hi RSenior,
Thanks for your post! Your approach is definitely more efficient.
Regards,
12-11-2012 11:08 AM
Thanks everyone for all your help, I really appreciate it.