LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Auto-indexing 2-D array into For Loop - what happens?

Solved!
Go to solution

I have found many sources that discuss 1-D arrays into a For Loop or While Loop using auto-indexing but nothing about higher-order arrays.

 

I am working with a program that feeds a 2-D array into a While Loop (see attached).  From what I can see, it looks like that the auto-indexing results in a 1-D array, the first column of the 2-D array.

 

Is this the expected behavior and should it hold true for higher-order arrays, e.g. 3-D array?

 

Is there any way to designate that one wants the second column rather than the first?

0 Kudos
Message 1 of 8
(6,498 Views)
Solution
Accepted by wildcatherder

@wildcatherder wrote:

I have found many sources that discuss 1-D arrays into a For Loop or While Loop using auto-indexing but nothing about higher-order arrays.

 

I am working with a program that feeds a 2-D array into a While Loop (see attached).  From what I can see, it looks like that the auto-indexing results in a 1-D array, the first column of the 2-D array.

 

No.  It auto-indexes through the array one row at a time.  You'll get a 1-D array that consists of all the columns that make up each row on each iteration.

 

Is this the expected behavior and should it hold true for higher-order arrays, e.g. 3-D array?

 

Yes.  Auto-indexing on a 3-D array will give you a 2-D array on every iteration consisting of each page.

 

Is there any way to designate that one wants the second column rather than the first?  This question doesn't apply once you understand the first response.


 

Message 2 of 8
(6,487 Views)

The autoindex iterates over the lowest dimension.  So when you autoindex over a 2D array, the rows will be indexed.

 

I'm not sure what you mean by the "second column".  Do you mean dimension?  There is the transpose 2D array function that will swap your rows and columns.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 3 of 8
(6,483 Views)

Actually, I would argue that it iterates over the "highest dimension".

 

In a 3-D array, the indices at the left of the control are page, row, column in that order from top to bottom.  If you have an Index Array connected to the 3-D array, then the order of the index inputs are also, page, row, column from top to bottom.

 

A 2-D array, is row, column in that order from top to bottom.  A 4-D array is volume, page, row, column.

0 Kudos
Message 4 of 8
(6,477 Views)

So, you're saying I should get pairs of data in the 1-D output array (using the indexes of the original 2d array):

 

0,0

0,1

1,0

1,1

2,0

2,1

3,0

3,1

 

?

 

I'm asking because I can't get the big program to run yet.

0 Kudos
Message 5 of 8
(6,474 Views)

If you have an array defined as:

[1,2,3

 4,5,6]

 

and autoindex it, you will get [1,2,3] then [4,5,6].  If you want to index over the columns (ie get [1,4], [2,5], and [3,6]), you need to transpose the array before going into the loop.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 6 of 8
(6,467 Views)

@Ravens Fan wrote:

Actually, I would argue that it iterates over the "highest dimension".


Semantics.  But I am inclined to agree with your definition here.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 7 of 8
(6,466 Views)

I believe I understand it now.  

 

I have attached a working example for LabVIEW 2011.  It's a lot easier to see this way. Input 2_D is a 2-D array constructed so there are unique values in row and columns, making it easier to identify how the elements are reorganized into the Auto-indexed 1-D array.  It cycles on a 3-second timer.  It is evident that a row at a time is processed into Auto-indexed1-D array.  The row element goes into index 0 and the column element goes into index 1.  Only the first two elements will ever be used, in this case.

 

Thanks for the help.  I hope my example makes it easier for the next person who has this question. 

0 Kudos
Message 8 of 8
(6,452 Views)