LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to remove empty columns in an array

I'm building an array of data that is eventually written to a .csv using Write Delimited Spreadsheet. I am looking for a way to remove empty columns in a 2D array so that I don't end up with excess trailing commas in a .csv. I can't just remove all empty elements, because some columns are deliberately empty. But all columns without a header are not supposed to be there. They do seem to always occur at the end of the array, but the number of these varies so implementing a "remove last 3 columns", for example, isn't going to work in every case.

data structure.PNG

 

I'm not 100% sure what's causing the array to have extra columns, because I initialize to a specific size and then a series of insert into array steps are creating the unwanted excess. My code is basically this code snippet inside a for loop to read a series of selected spreadsheet columns into my array; paring a larger multi-instrument log file back to look at only certain channels. Until I can track the issue down, I'm curious to hear creative solutions to removing entirely empty columns only.

0 Kudos
Message 1 of 6
(1,325 Views)

What's the LabVIEW code handling the data look like?

 

My guess is that at some point there's a row that has more columns then you're expecting and LabVIEW arrays must always be rectangular. First, I'd hunt down the originating source of the extra columns. It should feel a bit sloppy to say "I don't know where these extra columns are coming from so I'll just delete the extra ones". You should know where they're coming from. We won't be able to tell from a generated CSV file.

 

If you know the source of the extra columns and you need to keep that for some reason, you can just subset the array to the number of columns you want:

asb.png

 

~ Self-professed LabVIEW wizard ~
Helping pave the path to long-term living and thriving in space.
0 Kudos
Message 2 of 6
(1,317 Views)

@IlluminatedG wrote:

What's the LabVIEW code handling the data look like?

 

My guess is that at some point there's a row that has more columns then you're expecting and LabVIEW arrays must always be rectangular. First, I'd hunt down the originating source of the extra columns. It should feel a bit sloppy to say "I don't know where these extra columns are coming from so I'll just delete the extra ones". You should know where they're coming from. We won't be able to tell from a generated CSV file.


Yes, I am aware that the obvious solution is to extirpate the problem at the source, and I am doing that. However, I still have a bunch of old logs to rectify and I am separately curious about how one would remove only empty columns from an array in LabVIEW. This is why I shared only the data and not the code. If this specific task can not be completed in LabVIEW, I will know to go to another language in the future. But I really doubt that's necessary, hence why I am asking for advice here.



To @Markprince, I believe you're suggesting things in python, and that will certainly work as a backup, so thanks.

0 Kudos
Message 3 of 6
(1,244 Views)

Hi sbernie,

 


@sbernie2 wrote:
However, I still have a bunch of old logs to rectify and I am separately curious about how one would remove only empty columns from an array in LabVIEW. This is why I shared only the data and not the code. If this specific task can not be completed in LabVIEW,

LabVIEW is a programming language and you can do almost anything with it.

The question is: what have you tried and where are you stuck?

 

Suggestion:

GerdW_0-1675881530708.png

 

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 6
(1,231 Views)

@sbernie2 wrote:



To @Markprince, I believe you're suggesting things in python


Yes, that's because it was actually a spammer, so you start with content which looks as legitimate as possible without requiring any actual effort (e.g. copy and paste a reply from somewhere else that's hopefully about the same topic) and then you try to sneak your spam links in without people noticing.


___________________
Try to take over the world!
0 Kudos
Message 5 of 6
(1,185 Views)

@sbernie2 wrote:

I'm not 100% sure what's causing the array to have extra columns, because I initialize to a specific size and then a series of insert into array steps are creating the unwanted excess. 


Showing code would help.

 

Insert into array inserts a row or column, moving the existing data. If you create an empty array with a specific size, and insert into that, the array will grow. The empty array elements will move to the right or bottom.

 

Don't use insert, but use replace array subset.

 

Or, don't initialize with a size, and insert into an (initially) empty array.

0 Kudos
Message 6 of 6
(1,176 Views)