LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Programmably delete empty column in 2d array

How to programmably delete all empty column in 2 dimensional array

0 Kudos
Message 1 of 17
(6,578 Views)

For each column

   If column NOT empty

       Include in output array

 

Use the CONDITIONAL option on the output tunnel.

 

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


Blog for (mostly LabVIEW) programmers: Tips And Tricks

Message 2 of 17
(6,565 Views)

Here's a postage stamp code using OpenG.

 

Example_VI_BD.png

 

EDIT: Made by own Rube.  Instead of OpenG and is empty array, you can use the Empty String/Path primative, and the And array Elements.

0 Kudos
Message 3 of 17
(6,545 Views)

Note that you cannot have a truly empty column in an array. You can have a column with all default values for the element datatype. This is what the previous responses have shown.

 

Lynn

0 Kudos
Message 4 of 17
(6,526 Views)

Here is a solution that I think will work for me.

Based on Coastel's logic

 

 

0 Kudos
Message 5 of 17
(6,498 Views)

@quexin wrote:

Here is a solution that I think will work for me.

Based on Coastel's logic 


Yeah that won't work at all.  In LabVIEW arrays have the same number of rows in all columns, and the same number of columns in all rows.  If you index out a column (like you are) it will always be the same size as all the other columns, so if one is empty they all are empty, if one of them is not empty, then all of them will not be empty.

 

There is also some Rube-like code because if you want to index columns just use the transpose like I showed, and use indexing terminals going into the for loop.  If you want to know the number of rows and columns, you can also use the Matrix Size instead of size and index, and did you mean to run the loop one minus the number of rows, but index columns?  Oh and what is with the case structure?  If True make false if false make true?  Just remove the case structure.

Message 6 of 17
(6,490 Views)

If you think it will work, you should try running it before posting it.  Then you'll find out it doesn't work at all.

 

First you have a Rube Goldberg in there that the True and False cases are identical.  Second, your "Is Empty" won't work because your array isn't empty.  It is a column full of empty strings, but the the column itself isn't empty.

 

This is what will work with a lot less code.

 

Message 7 of 17
(6,470 Views)

First of all, you have to define what "empty" means.

As johnsold said, there really is no such thing.

 

If the column exists, then it is not empty.  Period.

 

You might mean "contains only zeroes", or "contains only blank strings", but that's not the same thing as "empty".

 

Don't even TRY to write code until you define in your head what you mean by "empty".

 

So, my code works:

 

For each column

   If column NOT empty

       Include in output array

 

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 8 of 17
(6,464 Views)

I wonder if this is an example of Cunningham's Law.

 

"The best way to get the right answer on the Internet is not to ask a question, it's to post the wrong answer."

0 Kudos
Message 9 of 17
(6,457 Views)

The best way to delete empty columns is to not generate empty columns.

 

What part of your code generates this 2D array?

0 Kudos
Message 10 of 17
(6,430 Views)