LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Concatenate arrays

Solved!
Go to solution

Hello everyone,

 

I have a question that I cannot solve.

 

I have two files with different size columns and rows, these files are modified so that they both have 7 columns, but the same number of rows as the original file.

This information must be seen in a table, the problem is, when joining the two arrays a 6x14 matrix is ​​created:

Mocte117_2-1688182290328.png

and I need to create a matrix with all the rows (N) of both files and 7 columns:

Mocte117_3-1688182334846.png

I already tried to use some array functions like index array or reshape array, but this didn't work for me.

 

How can I do this?

 

The code:

Mocte117_0-1688182191360.png

 

0 Kudos
Message 1 of 9
(2,084 Views)

Hi Mocte,

 

right now you build one row from each file and then you concatenate those rows to one large row...

Instead you should build a 2D array from those two rows to place them "one over the other"...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 9
(2,045 Views)

Example:

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 3 of 9
(2,027 Views)

I've had to do similar Array Manipulations, most recently when trying to assemble data from an FPGA managing 16 16-bit A/D converters taking 100 "bursts" of 3 A/D samples at 20 kHz.  I needed to combine these 3-D arrays of "bits" into a 2D Array of "300 A/D Samples from AI0 through AI15".

 

What I did was to write a little LabVIEW "data-generating" routine to create models of the data coming in and then write routines that I thought would "assemble" the data for me correctly.  But how to tell?

 

Your problem is similar.  You have two arrays with 6 rows and 7 columns, and you want to combine them into one array with 12 rows and 7 columns.  How will you know you've not only created a 12 x 7 Array, but the values are "where you want them to be"?

 

Do what I did.  Write a little LabVIEW routine that generates the "test arrays" (the two 6 x 7 arrrays) in such a way that you can easily identify their contents and tell if they end up in the right place.  What's an easy way to tell?  Consider Array 1, and the entry in Row 1, Column 1 (I'm calling the upper left corner [1, 1] for convenience).  Put "111" (for Array 1, Row 1, Column 1) in there, and put "123" in Array 1, Row 2, Column 3.

 

Here's how I did this:

Self-Identifying Array.png

The Array number ("1") is the constant going into the For loop (where it gets multiplied by 100 to "move it over"), the Number of Rows ("6") is the "N" of the outer For Loop, and the Number of Columns ("7") is the "N" for the inner For Loop.

 

This is a VI Snippet.  If you open LabVIEW, you should be able to drag this .png image onto an empty Block Diagram and have runnable LabVIEW code appear.  [I'm not sure if you need to be running LabVIEW 2019 for this to work, but the VI is simple enough you should be able to recreate it for yourself.  Whenoff you run it, you'll see that the upper left corner entry of Array 1 is "111", and the lower right is "167", as expected.

 

Now, a trick.  Copy this block Diagram, and paste the copy just below the "Array 1" code.  Hey, it is generating Array 2!  You need to change the "1" (on the "Array 2" code to a "2", of course, but now you'll get both Array 1 and Array 2.  You can also explore changing the number of rows of Array to, maybe to 5 or 8 (keep it single digits, though).

 

So you now have two arrays.  What do you want to do to combine them into a single Array?  There's a LabVIEW function that does precisely that, takes two Arrays and creates a third.  Do you know which one I mean?  Build Array.  Try it on Array 1 and Array 2 to create "Combined Arrays".  Is this what you want?  If not, right-click "Build Array" and examine the pop-up options that appear.  If you still don't see it, click "Help" and read the first sentence of the Description (pay attention to the first word).

 

Bob Schor

Message 4 of 9
(2,010 Views)

LVNinja_0-1688222193702.png

 

Message 5 of 9
(2,006 Views)

While the entire thing could be simplified more, here's a solution with "minimally invasive surgery":

 

Just move the concatenate array outside the loop and make the two tunnels indexing:

 

altenbach_0-1688222390404.png

 

Unless you can guarantee that both files always have the same number of rows, each should have it's own FOR loop, then do as above. Else, the shorter file wins and data is lost.

 

(I did not understand the need for the while loop to read and process the same files over and over, millions of times per second, so I removed it.) 

 

Message 6 of 9
(2,004 Views)
Solution
Accepted by Mocte117

@altenbach wrote:

Unless you can guarantee that both files always have the same number of rows, each should have it's own FOR loop, then do as above. Else, the shorter file wins and data is lost.

 


I fact your two input files have different numbers of rows, so if you want to get all data, you need two loops as e.g. follows:

(note that you only need to wire the indices that are out of order)

 

altenbach_0-1688223988088.png

 

Message 7 of 9
(1,992 Views)

If the processing depends on the name of the top-left header element (C1 vs M1), here's a more scalable solution that you can easily expand. (add more files, add more processing options, etc.). In fact you could process an entire folder full of hundreds of files using "list folder" with a desired pattern (e.g. Data*.txt) with very little change in code.

 

It also eliminates a lot of duplicate code.

 

altenbach_0-1688224890641.png

 

 

 

 

 

Message 8 of 9
(1,986 Views)

@altenbach wrote:

 In fact you could process an entire folder full of hundreds of files using "list folder" with a desired pattern (e.g. Data*.txt) with very little change in code.


Here's how that could look like (Of course now you get the files in alphabetical order).:

 

altenbach_0-1688225424107.png

 

Message 9 of 9
(1,980 Views)