10-07-2016 09:39 AM
First time user having an issue appending data to an array in a for loop. Only data that was read during the last pass through the for loop appears in the file. Any ideas/solutions would be be great.
10-07-2016 09:51 AM - edited 10-07-2016 09:55 AM
The loop tunnel is set to Last value hence last value only, You can use indexing option to get for all indices values.
Edit: Here you go for learning:
LabVIEW Graphical Programming Course
10-07-2016 11:22 AM
I agree with Uday that you need to take the basic Tutorials, paying especially close attention (this time) to While and For Loops, Arrays, and the types of Tunnels in and out of loops.
Your Post's title says "Appending data to an array". You usually append data with Build Array, and keep the growing array inside the loop in a Shift Register (learn about these in the "Loop" tutorials). What you are doing is generating a single Array element each pass through the loop, and you want to build the entire array when you exit the loop. This I would call "Building an array of data" (there is no "appending", and the Loop Tutorial will explain that you use an Indexing Tunnel for this purpose (look closely at its symbol -- it is a box surrounding a pair of square brackets, a symbol for an Array).
Bob Schor
10-09-2016 06:18 AM
uday
Thankyou for the links, I'll check them out. Chris
10-09-2016 06:27 AM
Bob
Thanks for clarifying the array issue. I'll look into the tutorials that Uday listed and pay attention to the areas that you pointed out. Thanks, Chris
10-09-2016 09:32 AM
Bob
Not sure how to procede with correctly building the array. Spent the evening viewing tutorials, but all seemed much differrent than my application. If you have the time, could you provide some guidence? Thanks, Chris
10-09-2016 11:19 AM - edited 10-09-2016 04:51 PM
It really depends what you mean by "building". You already have an array of waveforms, so how do you want to append things? Your question is quite ambiguous. One interpertation would be to keep an array with the same number of elements, but to append to each waveform as new data is received. Another option would be to skip the building and write to file at each iteration. So tell us what you have in mind.
In any case, most of your code is extremely convoluted and inefficient. Way too much code! For example the way to scale two of the waveforms and splice out the graphs and table from the array could prpobably be done in a significantly easier way (see image).
10-09-2016 04:40 PM
Re: More convoluted and needless code:
The array functions are inplace anyway and math primitives accept waveforms. With the DAQmx Create Channel.vi See that "name to assign" input? Also, do not configure tasks and stop them inside a loop its sort of pointless to stop a finite task after reading it anyhow.
That gets rid of a lot of junk code
10-10-2016 03:32 PM
altenbach
Thanks for taking the time to point things out. This is my first time working with Labview. It has been an eye opener. Once I become more comfortable and understand the enviroment, I should come up with efficient code. Not this time though as you have pointed out. My goal is the read all channels many times determined by the for loop, keep the same number of elements, and append to each waveform as new data is received. Thanks again, Chris
10-10-2016 03:46 PM
Jeff
Thanks for pointing out all that I have not understood. I'll spend the evening studying what you have created. Chris