LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Append 2, 1D arrays. I need to transpse a 1D array.

Solved!
Go to solution

I know a 1D can't be transposed.. but it needs to be to add to the existing. as in the image.. as I am saving to txt then opeing it in excel and i need Array 1 LONG and Array 2 to be beside each other.. All data and Important data. both in the same sheet. 

Download All
0 Kudos
Message 1 of 13
(468 Views)

Your VI does not contain any typical default data, so we need to guess. (It also really helps to use smaller arrays with recognizably different data instead of long arrays with very similar values to avoid confusion.)

 

Maybe this will help?

 

altenbach_0-1744821922548.png

 

 

A few notes:

  • When autoindexing on arrays with different lengths, the shorter always wins. No need to wire N.
  • When building a 2D array from 1D arrays of different length, the longest always wins.
  • Ragged arrays are not supported, so all columns in the result will be of equal length, padded with the default value of the datatype (empty string, zero, etc.)

 

 

 

0 Kudos
Message 2 of 13
(460 Views)

I'm afraid Altenbach did not answer your question. You can't do what you're trying to do. You need two output arrays. Just append your two arrays as one of your outputs (the concatenation of the truncated arr1 and arr2). Your other output output looks to be just array 2. If you need them in the same data struct, you can get something like a 2-D array of different lengths by putting each 1-D array in a cluster and making an array of those clusters.

littlesphaeroid_0-1744824278954.png

 

_____________
Creator of the BundleMagic plugin for LabVIEW!
0 Kudos
Message 3 of 13
(439 Views)

If what you want to do is to add a 1D array "to the end" of a 1D array, that's called "Concatenate" Arrays.  It is like "Append Array", but you right-click the function and choose "Concatenate".

 

Bob Schor

Message 4 of 13
(437 Views)

I apologize for not reading your post carefully.  One thing about LabVIEW Arrays (and, as far as I know, is generally true for multi-dimensioned arrays in most Programming Languages) -- they must have "square edges", that is, for a 2D Array, all rows are the same length and all columns are the same length.  It is legal to not use all the rows/columns by putting a "No data here" entry in an unused cell (for strings, this would be leaving the cell blank, for integers, it might be putting a 0 or -1 in the cell, for Floats, putting NaN in the cell).  In your case, you show a picture (which at least lets me see the color of the wire, pink, suggesting you are saving Strings) which suggests a blank cell would work.

 

So if you have a N x 2 (N rows, 2 columns) Array and you want to "add to the end" a M x 1 set of data, you would do two steps:

  1. Change the M x 1 Array into an M x 2 Array by doing the following:
    1. Use Array Size to get M, the size you need.
    2. Use Initialize Array to create an M x 1 Array of blank spaces.
    3. Use Build Array to the two M x 1 Arrays into an M x 2 Array (note the change in the wire, showing you have a 2D Array).
  2. Now use Build Array with the Concatenate option to combine you N x 2 and M x 2 Arrays into an (N+M) x 2 Array.

I'm not attaching code nor a picture because I think the ideas of how Arrays work is more important to your getting the hang of LabVIEW (and programming), so I used "words" instead.

 

Bob Schor

0 Kudos
Message 5 of 13
(424 Views)

@littlesphaeroid wrote:

I'm afraid Altenbach did not answer your question.


I am "afraid" I did, because I said in the notes that ragged arrays are not supported. Since these are string arrays, padding with empty strings looks OK (numeric arrays would pad with zeroes). Excel will not care!

 

If we want fewer delimiters for the shorter excel rows, we could e.g. do e.g. as follows (Yes, it can be simplified in many ways!)

 

altenbach_0-1744844341001.png

 

 

 

I was under the impression that the result should again be saved as excel, which would required quite a bit of gymnastics to process a 1D array of clusters of arrays. Sorry, I cannot look at your VI, because I only have access LabVIEW 2020 at the moment).

 

(there are also problems with the data itself, for example the longer arrays seems to have extra lines, judging from the overflow indicator)

 

0 Kudos
Message 6 of 13
(413 Views)

Not sure why the picture didn't come through inline with text.. so try 2. I need to append a 1d array to a 2d array, BUT the 1D array is coming out as a column, not a row, See pic below.. 

As to the solution, I'm running LV 2019 and it's in 2023 so I can't open it.. Can you save as "previous version" so I can check it out

 

Thanks again

 

nrcan_0-1744888441375.png

 

0 Kudos
Message 7 of 13
(380 Views)

Your "What I Want" result isn't achievable.

 

Each row and each column get's the same size (e.g. the 2D array is a square of data).

 

It would make things a lot clearer if the elements in your example where not random numbers...

 

wiebeCARYA_0-1744890169547.png

wiebeCARYA_0-1744890331122.png

 

0 Kudos
Message 8 of 13
(376 Views)

SORRY! I didn't realize my arrays where not saved in the original post.. here are the arrays with the test data. 

0 Kudos
Message 9 of 13
(362 Views)

Thanks!  Now I can "see what you've done" and can also "see what remains to be done".

 

I had not run your code, nor "made my own version to test" (because I have my own work to do), but now I understand your problem and realize you didn't "get" my original suggestion.  So I'll explain how to "understand" your code, and how to "fix it" so that the "Need to append" piece can be turned into an "Appendable piece".

 

Your first (minor) error was to wire the size of one of the Arrays to the "N" terminal of the For Loop.  You (correctly) chose to use the size of the smaller array, but if you left it unwired, you would have gotten the same "upper part" because the For Loop is made to stop when any Indexing Tunnel runs out of elements!  So the Upper Part will be "correct" with N unwired.

 

So now you need to make a Correctly-sized 2D Array to append the "remaining elements" that are "missing" from the Upper Part.  You "correctly" extract those remaining elements by using Array Subset, with Array 1 as the Input and the Index being the size of Array 2, which gives you "Need to Append".  Now you have to turn this into an N x 2 array, with the first column being "Need to Append" and the second column being the Empty String constant.  Simple -- wire "Need to Append" to "Array Size" (to get how many elements).  Drop down an Initialize Array, with Empty String Constant as the Array Element and the Dimension Size coming from the Array Size function.  Now you have two N element Arrays, one "Lower Part" (from "Need to Append") and one all Empty String Constants.  Go do a Build Array.  Now look at the size of that Build Array -- oops, it's 2 x N (because you "built" it from two (1 x ) N Arrays).  How do you fix that?  [Look through the Array functions and figure out which one turns this into an N x 2 Array.]

 

Now you have an N x 2 Array, the first column being all the entries in Array 1, and the second being all the entries in Array 2, with blanks after there are no more Array 2 entries.

 

Go fix your code.

 

Bob Schor 

0 Kudos
Message 10 of 13
(346 Views)