LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Using a For Loop Index for Array Element Number?

Hi.  Thanks in advance for the help.  I can't seem to find what I want to do here using the search function... probably because I don't know how to frame the question appropriately.  Ignore the title to this post cause it's probably wrong vocabulary for what I want to do.

 

Here's the situation:

 

I have a 2D array where the first column is the X data and each subsequent column is Y data (call it Y1...Yn).  The n-value varies from run to run (some runs have 4 columns of data, some have 20), but that is easily gathered when reading the data file.  I need to perform a number of operations on each set of data, the least of which is smoothing the data and graphing it, so I'm limiting my discussion to these 2 operations.

 

What I want is a for loop structure where the indexing of the loop tracks the Y1...Yn columns, grabs each column for the iteration, performs the relevant analysis, and spits out the result, but in a stackable manner.  Thus the title; I want to use the for loop's index to mark the array element for building a new array.

 

See the image attached.  A 2D array of 9 columns (X, Y1...Y8) is analyzed such that each data set, (X, Y1), (X, Y2)...(X, Y8) is bundled, graphed, run through a B-spline Fit, of which is also graphed.  I need to replace this with something that looks like the for loop structure shown.  

 

I just don't know how to get those two data bundles [(X, Yi) and it's smoothed pair] out of the for loop in a stacked set from every iteration of the for loop.

 

Again the title, I think I want to build a new array where i use the index of the for loop to control the entries of the new array.  But I can't see how to do that.

 

Any help would be appreciated.

0 Kudos
Message 1 of 7
(4,894 Views)

Hello H.R. Dunham, and welcome to the forum!

 

It seems that you may be looking for Auto-Indexing, a basic feature of loops in LabVIEW.  You'll need to transpose your array before wiring it into the for loop, as elements are auto-indexed by row before column, but at that point you should be able to operate on each column and output an array of n cluster elements corresponding to your input columns.  Auto-indexing tunnels look like brackets to indicate each element will be indexed automatically- this should be the default when wiring an array into a for loop or when wiring anything out of a for loop.

 

As for how to build your pairs, I suggest removing the X column and creating a "starter" cluster containing your X data and placeholder Y data before entering your "Y" processing loop.  Use the bundle by name function in the for loop to insert your processed column data into the cluster and auto-index the cluster output. Flow would be something like this:

 

1) Gather data

2) Split X and Y using standard array operations

3) Create "template" cluster with shared X data

4) Pass template cluster and Y-column array into an auto-indexed for loop.

5) Insert processed Y data into cluster inside loop.

6) Auto-index cluster data out of loop.

 

This tutorial is probably also a good place to get started:

 

Getting Started with NI LabVIEW Module 3: Loops

http://www.ni.com/white-paper/7528/en/

 

Hope that helps!

 

Regards,

Tom L.
0 Kudos
Message 2 of 7
(4,868 Views)

I'm not sure I understand... it looks like the image you posted is the exact solution.  You just run the wire out and it will auto index and build an array.

0 Kudos
Message 3 of 7
(4,866 Views)

Thanks for the reply 0utlaw, but auto-indexing isn't working for me.  Here's why:

 

The index is based of the number of data columns.  As you can see from the attached image in the OP, I'm generating twice as many graphs (one for the raw, one for the spline) for each iteration.  So using auto-indexing only gives me half the graphs of what I need.  As I stated in the OP, graphing the raw data and the spline are only 2 of the many things I need to do.

 

What I really want is a a way to grab the index, and use that as a control of the element number for the build array.  As an example, for the 0th iteration, I'd like to grab columns 0 and 1, bundle, and force that to element 0 of the array, then make their spline and force that to element 1 of the array.  Each iteration these would increment by 2, so the 1st iteration would force to element 2 and 3, etc.

 

Auto-indexing is just that, automatic.  What I need is a way to modify the index and use it as a designator of the element number so the array gets slotted in the right spot in the new array.

 

If that made sense...

0 Kudos
Message 4 of 7
(4,845 Views)

Then you can't use autoindex.

 

Set the For Loop to run the size of the array divided by two.  (Quotient Remainder is useful here.)

 

Set you index array to take the i value times two.  Extend index array down and you'll automatically get the one after it as well.

 

So iteration 0, you get rows 0 and 1.

Iteration 1, you get 2 and 3

iteration 2, you get 4 and 5.

0 Kudos
Message 5 of 7
(4,834 Views)

Hi RavensFan.

 

Sorry, but that doesn't help at all.  Please re-read the OP.  I have to have column 0 every iteration as it's the X value for each subsequent column, Y1...Yn.  Each iteration I need to capture X and Y(i+1).

 

Attached is what happens with auto-indexing.

0 Kudos
Message 6 of 7
(4,819 Views)

The reason you get not enough plots is that you've used shift register, where you've should use auto indexing as well... Here's other way to do it (using auto indexing at input terminal as well)

0 Kudos
Message 7 of 7
(4,801 Views)