09-04-2009 06:47 AM
Hi,
I am trying to find outliers in my dat file by the following:
outLyIndx = ChnFind("Ch("""&cname&""")<-3 OR Ch("""&cname&""")>"&str(uplimit))
In my data file, I have a value which is in the range below -3. However, the above code does not seem to work. I am trying to locate values which are outside a particular band. In this case it is less than -3 and more than the value of the variable 'uplimit'. I would also like to replace the lower limit by a variable.
Any suggestions?
09-04-2009 10:25 AM
Hi dvjravikumar,
The first problem is that you have 3 double-quotes (""") instead of 2 ("") in your code. The second problem is that your variable "uplimit" must be declared as a global DIAdem variable (with GlobalDim) in order to work in the ChnFind() or ChnCalculate() functions. Alternatively you can use the global L1, R1, etc. temporary variables that DIAdem always creates for you when it starts up. The third problem is that without adding the second parameter (start index) to the ChnFind() command, you are doomed to find only the first out of range value-- plus you would need to loop over the ChnFind() function until it got to the end of the data channel. Probably the better approach is to use the ChnCalculate() function to create a new channel in the Data Portal that contains all the out of range values. You could run the ChnCalculate() function multiple times to also find the X values that correspond to the naughty Y values or to put the high outliers in one channel and the low outliers in a different channel. Here's how that works:
L1 = CNo("[1]/Revs")
R1 = 3000
R2 = 5000
Call ChnCalculate("Ch(""Outliers"") = Ch(L1) + CTNV(Ch(L1)<R1 OR Ch(L1)>R2)")
Brad Turpin
DIAdem Product Support Engineer
National Instruments
09-04-2009 11:33 AM
Hello!
I tried it and it worked as expected. Can you provide me your data to test against it. Wich version of DIAdem do you use?
Matthias
Matthias Alleweldt Project Engineer / Projektingenieur | Twigeater? |
09-04-2009 11:51 AM
Hello Brad!
I think that this is one of the rare moments you are not completly right If you just try to print the expression in a message box you will see that it is OK. The triple " will wrap the channel name as necessary.
Matthias
Matthias Alleweldt Project Engineer / Projektingenieur | Twigeater? |
09-08-2009 07:15 AM - edited 09-08-2009 07:17 AM
Hello Brad and Twigeater,
I happened to get in touch with dvjravikumar, and seems like he was unable to post his reply. He had sent me the script and am posting the same here.....
'-------------------------------------------------------------------------------
'-- VBS script file
'-- Created on 09/02/2009 15:22:40
'-- Author: ---
'-- Comment: ---
'-------------------------------------------------------------------------------
Option Explicit 'Forces the explicit declaration of all the variables
in a script.
Dim MyFolders()
Call InitMyFolders
'-------------------------------------------------------------------------------
Sub InitMyFolders
ReDim MyFolders(1)
'MyFolders(0)="E:\users\ADC24DS121\INL\New Folder\New Folder\"
MyFolders(0)="E:\users\ADC24DS121\INL\inl4\"
End Sub
'-------------------------------------------------------------------------------
Call DataDelAll(1)
Dim
i,j,k,outLyIndxLo,outLyIndxHi,chavg,cname,AM,l,lolimit,uplimit,outLyIndxSD,outLyIndx0,ADC_err
j=0
i=0
For i= 3 to 8003 step 16 'steps through the files.
Call
DataFileLoadSel(MyFolders(0)&"air_cobra_vos_test_1_0_090814_194222_raw_data_0_"&i&".csv","CSV","[1]/[6]")
Call
DataFileLoadRed(MyFolders(0)&"air_cobra_vos_test_1_0_090814_194222_raw_data_0_"&i&".csv","CSV","[1]/[5]","IntervalWidth",1000,eInterMeanValue)
if j=0 Then
Call
ChnAreaDel("air_cobra_vos_test_1_0_090814_194222_raw_data_0_3/vadc",1,100)
'Deletes first 100 points
For k = 1 To 23
StatSel(k) = "No"
Next
StatSel(6) = "Yes" ' Arith. mean
StatSel(14) = "Yes" 'Standard Deviation
Call StatBlockCalc("Channel","1-900","vadc")
ADC_err = ChnSub("vin_Mean","ArithmeticMean")
Else
Call
ChnAreaDel("air_cobra_vos_test_1_0_090814_194222_raw_data_0_3/vadc"&j,1,100)
For k = 1 To 23
StatSel(k) = "No"
Next
StatSel(6) = "Yes" ' Arith. mean
'StatSel(14) = "Yes"
Call StatBlockCalc("Channel","1-900","vadc"&j)
cname = "vadc"&j
chavg = CHD(1,"ArithmeticMean"&j)
uplimit=chavg+30e-03
'uplimit=-3
'lolimit=-5
lolimit=chavg-30e-03
For l=1 to 5
'outLyIndx = ChnFind("Ch("""&cname&""")>" &str(test))'This works
'outLyIndx = ChnFind("Ch("""&cname&""")>" &str(chavg))'This works
'outLyIndx = ChnFind("Ch("""&cname&""")<-3")' This works
'outLyIndx = ChnFind("Ch("""&cname&""")>-3 OR Ch("""&cname&""")<-5")'
This works
'outLyIndx = ChnFind("Ch("""&cname&""")<-3 OR
Ch("""&cname&""")>"&str(uplimit))'This works
'outLyIndx = ChnFind("Ch("""&cname&""")<""&str(lolimit)""OR
Ch("""&cname&""")>"&str(uplimit))'No syntax error,logical error
'outLyIndx = ChnFind("Ch("""&cname&""")>""&str(uplimit)"" OR
Ch("""&cname&""")<"&str(lolimit))
outLyIndx0 = ChnFind("Ch("""&cname&""")=0")
outLyIndxLo = ChnFind("Ch("""&cname&""")<"&str(lolimit))
outLyIndxHi = ChnFind("Ch("""&cname&""")>"&str(uplimit))
if outLyIndx0 <> 0 Then
CHD(outLyIndx0,"vadc"&j) = NOVALUE
End if
if outLyIndxLo <> 0 Then
CHD(outLyIndxLo,"vadc"&j) = NOVALUE
End if
if outLyIndxHi <> 0 Then
CHD(outLyIndxHi,"vadc"&j) = NOVALUE
End if
Next
Call ChnDel("ArithmeticMean"&j)
StatSel(6) = "Yes" ' Arith. mean
StatSel(14) = "Yes"
Call StatBlockCalc("Channel","1-900","vadc"&j)
ADC_err = ChnSub("vin_Mean"&j,"ArithmeticMean"&j)
Call ChnConcat("StandardDeviation"&j,"StandardDeviation" )
Call ChnConcat("vin_Mean"&j,"vin_Mean" )
Call ChnConcat("Subtracted"&j,"Subtracted" )
End if
j=j+1
Next
outLyIndxSD = ChnFind("Ch(""StandardDeviation"")>1e-03")
if outLyIndxSD <> 0 Then
CHD(outLyIndxSD,"StandardDeviation") = NOVALUE
End if
'Call ChnNovHandle(CALCXChn, CALCYChn, NovMeth, NovCtrlChn, [ChnNovIP],
NoVChnX, [NovReplaceVal])
dvjravikumar, I hope you are following the post.... there is some information which you have to provide us... Twigeater had requested for the same... Please post it....
Cheers!
Jayanth