LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Appending data to an array in a for loop

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.  

0 Kudos
Message 1 of 18
(13,925 Views)

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:

NI Learning Center

NI Getting Started

LabVEW Basics

3 Hour LabVIEW Introduction

6 Hour LabVIEW Introduction

LabVIEW Graphical Programming Course

Using the Context Help Window

LabVIEW Inbuilt Examples

Thanks
uday
Message 2 of 18
(13,917 Views)

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

Message 3 of 18
(13,893 Views)

uday

Thankyou for the links, I'll check them out.  Chris

0 Kudos
Message 4 of 18
(13,836 Views)

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

0 Kudos
Message 5 of 18
(13,833 Views)

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

 

0 Kudos
Message 6 of 18
(13,820 Views)

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).

 

 

0 Kudos
Message 7 of 18
(13,811 Views)

Re: More convoluted and needless code:

Rube Like This.png

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.

Capture.PNGCapture1.PNGThat gets rid of a lot of junk code


"Should be" isn't "Is" -Jay
0 Kudos
Message 8 of 18
(13,790 Views)

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

0 Kudos
Message 9 of 18
(13,753 Views)

Jeff

Thanks for pointing out all that I have not understood.  I'll spend the evening studying what you have created.  Chris

0 Kudos
Message 10 of 18
(13,750 Views)