LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Looping till end of column

Solved!
Go to solution

Hello!

 

I have a 2D array of type string that I'll want to loop through. The output of the array is feed to a "Scan from string" vi, and then converted to a timestamp. The problem is that the column in my 2D array is of different size. This means that some columns have some empty cells towards the end of the column. When this cells are feed to the "Scan from string", and error occurs. What I want is to either first search the array and remove all empty cells, or find some way to loop down the column and stop when the empty cells begin. The array is not fixed, so it is impossible to use some constant here. Can anyone help me on this one?:)

 

Greetings

Kristoffer

0 Kudos
Message 1 of 13
(2,691 Views)

How efficient do you need to be?

 

You can just check for an empty string and skip your loop operations if the cell is empty.

 

Alternatively, you could rework your 2D array to be a an array of clusters of 1D arrays.

0 Kudos
Message 2 of 13
(2,686 Views)

Well, it's a pretty large dataset, so I can't afford to be very unefficient.

 

When checking for an empty string, do you think of a loop inside a loop, or what kind of structure do you suggest?

 

Greetings

Kristoffer

0 Kudos
Message 3 of 13
(2,673 Views)

You need 2 loops: looping over rows and columns. The outer loop by default loops over rows - if you transpose array before, it will go - the internal loop will work with columns.

The internal loop can be stopped (starting from LV 2010 I suppose - "Conditional terminal' checkmark in the context menu)

or

you can search for an empty string to determine number of internal loop iterations

0 Kudos
Message 4 of 13
(2,664 Views)

I was thinking

Handle Empty Cell.png

 

But Alexander's suggestion is probably even better.  Just make the inner loop a "conditional for" and trigger off of the Empty String/Path?

0 Kudos
Message 5 of 13
(2,661 Views)

That seems good, but then I guess I'll  be needing something in the "True" section of the Case Structure that makes the looping change to the next column or something?

 

Alexander: Could you explain a bit more detailed, as I am not quite getting what you mean:)

 

Greetings

Kristoffer

0 Kudos
Message 6 of 13
(2,654 Views)
Solution
Accepted by topic author Sjefsgjogleren

Handle Empty Cell 2.png

 

Here's my interpretation of Alexander's solution.

Right Click on the Inner for loop to add the conditional terminal.

Message 7 of 13
(2,648 Views)

Ok, I get that one know!

 

I have attached how I am trying to solve it right now.

I am just wondering what you want to put inside the "True" case, as I can't figure it out!

 

Greetings

Kristoffer

Download All
0 Kudos
Message 8 of 13
(2,639 Views)

> I am just wondering what you want to put inside the "True" case, as I can't figure it out

Nothing (place Use default if unwired checkmark in terminal context menu). Some known constant to look for it later.

Also I would advise to store the number of valid elements in each dataset: not to do the same next time.

Or use Taki1999:

rework your 2D array to be a an array of clusters of 1D arrays 

- these arrays can have different sizes

 

BTW if you have data in columns, you need to transpose input (and output) array.

Message 9 of 13
(2,633 Views)

Thank you! I got it to work now, but it doesn't seems to be 100% correct. The size of the different columns in my array may vary. Column 0 might have 50 elements, column 1 might have 48, column 2 might have 52 and so on. When I use your program to convert the array from string to timestamp it seems that it is cutting of some of the values. As you can see from the attached picture, two samples has been "cut-off". Any solution to this problem?

0 Kudos
Message 10 of 13
(2,630 Views)