03-11-2014 01:01 PM
Hello,
I may have a question for scripting.
I would like to select cells (Chn_time lines) separated by a given number of cells (time increment, i.ei Step here 1) stored in a new channel (Chn1).
I can do the following:
Chn_time = Data.Root.ChannelGroups("time").Channels("time").Properties("name").Value
Chn1 = Data.Root.ChannelGroups("time").Channels("time").Properties("number").Value
counter=0
For j = 2 to ChLen Step 1 'loop over cells of channel
counter=counter+1
CHD(counter,Chn1) =CHD(j,Chn_time)
Next
But this is not optimal (too lenghty over crazy data)?
That would be of great help for me.
Thank you very much,
Louval
03-12-2014 05:47 PM
Hi louval,
I'm afraid I'm not understanding your goal with your request or with the code you provided. Why do you reference the same channel twice, once with the channel number and once with the channel name? Why are you overwriting that time channels values with it's own values from one row further down?
Brad Turpin
DIAdem Product Support Engineer
National Instruments
03-13-2014 04:55 AM
OK, so please let me reformulate.
What I want to do is simple: select lines every 'n' lines of channel (Chn_time) and copy them in a new channel (Chn_time_cut).
The correct version of the code I like to optimize (with data.tdm loaded) reads:
Dim counter, Chlen,Chn_time,Chn_time_cut, Grp1,j
ChLen = Data.Root.ChannelGroups("data").Channels("time").Properties("length").Value
Chn_time = Data.Root.ChannelGroups("data").Channels("time").Properties("numBer").Value
Call ChnAlloc("t_cut", ChLen,1,,,1)
Chn_time_cut = Data.Root.ChannelGroups("data").Channels("t_cut").Properties("number").Value
counter=0
For j = 2 to ChLen Step 1 'loop over cells of channel
counter=counter+1
CHD(counter,Chn_time_cut) =CHD(j,Chn_time)
Next
Cheers,
Louval
03-13-2014 08:10 AM
Hi,
If am I right, you want to copy channels?
If yes, use ChnCopy command:
Call ChnCopyExt("[1]/Chn_time",1,4).
Hope this helps!
Simyfren
03-13-2014 08:47 AM
It would too easy...
I do not want all the lines but only one every n line....
Louval
03-13-2014 08:50 AM
OK, and what problem do you have now?
Simyfren
03-13-2014 09:18 AM
Just Divide the length of the vector for the number of values that you want. Do the changes in Bold and it should be working, just Dim n and declare how many points of the original channel you want.
Dim counter, Chlen,Chn_time,Chn_time_cut, Grp1,j
ChLen = Data.Root.ChannelGroups("data").Channels("time").Properties("length").Value
Chn_time = Data.Root.ChannelGroups("data").Channels("time").Properties("numBer").Value
n = "number of steps"
Call ChnAlloc("t_cut", ChLen,1,,,1)
Chn_time_cut = Data.Root.ChannelGroups("data").Channels("t_cut").Properties("number").Value
counter=0
For j = 2 to ChLen/n Step 1 'loop over cells of channel
counter=counter+1
CHD(counter,Chn_time_cut) =CHD(j*n,Chn_time)
Next
03-13-2014 09:20 AM
If I do Call ChnCopyExt("[1]/Chn_time",1,4) I get all the line from Chn_time.
I do not want all the line, but one every n line with n=4 for instance.
Thank you,
Louval
03-13-2014 09:20 AM
However this will not give you a equidistant channel. Use "ChnLinGen" function instead.
03-13-2014 09:33 AM
well this is equivalent as setting:
For j = 2 to ChLen Step n 'loop over cells of channel
I would like to avoid using a loop to do it. But maybe this is the only way...
Louval