Logging Data to an array for later analysis


Recommended Posts

Hey, newbie here.

I would like to log data from a channel directly to an array for later analysis in another sequence.

The logging must begin at an event, at a rate of about 50hz (1 datapoint every 20 ms), and then stop after about 20 seconds. Which is the best way to do this? I know I can just create a logging channel, but I'd like to avoid writing the raw curve on my C: drive if I can.

Link to comment
Share on other sites

Easiest way is to create a second channel. Device type Test, I/O type A to D, Timing = 0. Let's call it myArray for this example. Then you'll need a global variable to mark the time of start of the event. Call it, say, eventStartTime. Then, in a button, say, to start the event, use a Quick Sequence action and put:

global eventStartTime = systime()

Then, in the Event for your input channel (I'll assume its called "inputChannel"), put:

if (systime() - eventStartTime < 20)


That is one way. You could also simply record the eventStartTime, then subset your input channel:

inputChannel[eventStartTime, eventStartTime + 20]

which will return an array of all the data points in "inputChannel" between the event start time and 20 seconds later.

Link to comment
Share on other sites

In your former example, if I wanted to trigger it from a sequence rather than a button, would I be able to trigger it as a Quick Sequence?

In your latter example, I would assume that the array size returned would depend only on the timing and the sample rate. So the returned array should have a size of 400 every time. Could I just set another array that has 400 elements in it, say arrayCapture, equal to it? e.g:

arrayCapture = inputChannel[eventStartTime, eventStartTime + 20]

would that work?

Link to comment
Share on other sites

In the former example: you can put the script wherever you want, either a Quick Sequence in a button, or in a regular sequence. It doesn't matter.

As for the later example, you are correct, though whether it returns 400 values or not doesn't really matter. inputChannel[eventStartTime, eventStartTime + 20] returns an array that you can do anything you want with, including assigning it to another variable. You'd have to do it AFTER the experiment was over of course. Note that arrayCapture can't be a channel. Note also that you don't have to declare the size of arrayCapture. Arrays in DAQFactory are auto-sizing.

Link to comment
Share on other sites


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