Accessing subsetted data from a channel


Recommended Posts

Hi,

I have an expression that is a subset portion of a channel that is entered to the X and Y expression boxes of the graph component. For example "MyXChannel[startTime,EndTime]" and "MyYChannel[startTime,EndTime]"

This plots out a nice scatter plot as an XY graph. I want to do a Least squares straight line fit to this subset of the data. Is there an easy way of getting at each data element to do the necessary maths? The two variables StartTime and EndTime are times in DAQFactory seconds as they are a user selected time slice out of the history/persisitance of the channels.

I started by using the graph analysis tool which enabled me to get the slope and intercept for the straight line fit into elements 0 and 1 of a V.Channel called V.Coefficients but now I want to do the fit in script so that the user doesn't need to mess about with the graph component or use the analysis tool.

I have the variables StartTime and EndTime. Is it OK to step through the channel using this time index or does it need to be converted to the actual channel index. The maths is pretty straight forward and the data usually consists of less than a hundred points as before the user is able to select a time slice the data has been averaged to limit the number of points plotted.

TIA

Martin

Link to comment
Share on other sites

Subsetting by time simply returns an array which you can then walk through element by element. That said, subsetting by time is slightly slower than by index, so its best to copy the result to a variable then walk through the variable:

private xchan = myxchannel[starttime, endtime]

private ychan = myychannel[starttime,endtime]

for(private x = 0, x < numrows(xchan), x++)

... etc, indexing into xchan and ychan by array index, not time

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.