From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

For loop Auto Index should not index empty array

Solved!
Go to solution

Hi guys,

In this VI, I meant to remove empty elements in array. It worked for 1D array but as soon as I gave it 2D array, for some reason I was unable to remove empty elements:

 

 

 

 

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

Try transposing the array before and after the for loop. Looks to me like it is indexing the other way round from what you expected...



Remember Cunningham's Law
0 Kudos
Message 2 of 7
(4,014 Views)

Hi cryptic username,

 

in an 2D array ALL rows need to have the same number of columns!

So even when you delete elements from row 2 it will still have two (empty) elements when row 1 has two ("non-empty") elements!

 

When you want to remove rows as well you need the same conditional output tunnel as you already use for the columns in the inner loop…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 3 of 7
(3,980 Views)

Hi GerdW,

So when I was debugging, I saw at the 3rd row and 4th row iteration, the output from inner FOR loop to index terminal of outter FOR loop is [].

 

 

I mean what you described definitely applies if [  ]  has some element but in this case it has none. To prove the point, try something like this:

 

 

 

 

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

Hi funny username,

 

 Why should it?

All it has to follow is DATAFLOW!

 

I mean what you described definitely applies if [  ]  has some element but in this case it has none.

It always behaves the same way. And it follows DATAFLOW!

 

To prove the point, try something like this:

Your example is WRONG as you compare apples with oranges!

In your first post you had non-empty 1D arrays and in your last post you have always empty arrays…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 7
(3,955 Views)
Solution
Accepted by topic author sdfsdfsdfadgadf

@sdfsdfsdfadgadf wrote:

 

So when I was debugging, I saw at the 3rd row and 4th row iteration, the output from inner FOR loop to index terminal of outter FOR loop is [].

 


In that case, the indexing tunnel in the outer loop takes an empty 1D array and appends it as a row to the 2D array. Because 2D arrays can't be jagged, it fills the remaining elements of the row (all of them) with the default value. You could possibly argue that an empty array should mean "don't append at all", but this behavior goes back a long way and I'm not sure what kind of effect this would have. As mentioned, it's easy enough to do what you want with a conditional append in the outer loop.

 

 


@sdfsdfsdfadgadf wrote:

 

I mean what you described definitely applies if [  ]  has some element but in this case it has none. To prove the point, try something like this:

 

 


Check the array size. You will find it is 3,0,0. That is, you have 3 pages, each with an empty 2D array, which is exactly what your code builds.

 

I try to avoid dealing with >2D arrays and dealing with cases where they can be empty, so I don't remember the details of why this happens, but IIRC, it does follow from the rules of the system.


___________________
Try to take over the world!
0 Kudos
Message 6 of 7
(3,916 Views)

Thanks 

0 Kudos
Message 7 of 7
(3,829 Views)