LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Split a 3D array into 3 1D arrays

Solved!
Go to solution

Hi all,

 

I'm trying to read a text file here and output the columns as three 1D arrays. Below is my program and the text file that I read. I was able to read it as a 3D array but unable to go on from there. The resulting arrays are three 2D arrays. Could someone help me please? 

 

Thank you.

 

Download All
0 Kudos
Message 1 of 14
(1,711 Views)

Sorry, posting by phone, cannot see your code.

 

Your file is a 2D array with three columns (and some headers).

 

You would use "index array" with the upper index disconnected and the desired columns index wired to the second index (resize as needed to get multiple columns).


LabVIEW Champion. It all comes together in GCentral GCentral
What does "Engineering Redefined" mean??
0 Kudos
Message 2 of 14
(1,707 Views)

Hi altenbach,

 

The text file is actually a 3D array. I did use index array but the result is not three 1D array as I said in my first thread. Here are screenshots of my block diagram and the front panel after I ran the program. 

Download All
0 Kudos
Message 3 of 14
(1,686 Views)

What would happen if you would change the array type input of "spreadsheet string to array"  to a 2D array?


LabVIEW Champion. It all comes together in GCentral GCentral
What does "Engineering Redefined" mean??
0 Kudos
Message 4 of 14
(1,680 Views)

Hi altenbach,

 

There will appear errors as shown in the second picture coming from the three index array functions and the program is not able to run. 

 

 

Download All
0 Kudos
Message 5 of 14
(1,677 Views)

Have you looked at the data file?  There are a few (text) rows that could be called "Headers" that you might want to eliminate before reading (so you only have rows consisting of three floating point numbers separated by commas).  There is only one "page" that can be decomposed into multiple "rows" and three "columns".  So you could consider it as a 3D array (row, column, page), but the "natural" interpretation is a 2D array (row, column).

 

So you have multiple rows (defined by lines of text) consisting of three numbers separated by a comma (or 3 columns).  A file consisted of values separated by commas, or a Comma-Separated-Value (or ".csv") file.  What LabVIEW calls a "Delimited Spreadsheet".  There is a specific function on the File I/O Palette to Read Delimited Spreadsheet -- if you put a file whose data are in .csv format (which is what you have once you get rid of the header rows), it will read the file and return, guess what?  A 2D array of floats.

 

Give it a try.  You might be amazed.  It really is 2D data, and there really is a simple LabVIEW function to read it.

 

Bob Schor

0 Kudos
Message 6 of 14
(1,675 Views)

Hi Bob_Schor,

 

I see what you mean by 2D array. My next question is then how would you go about extracting each column in the 2D array as a separate 1D array because I need to do calculations on them separately? 

 

 

0 Kudos
Message 7 of 14
(1,670 Views)
Solution
Accepted by topic author LindaLula

@LindaLula wrote:

I see what you mean by 2D array. My next question is then how would you go about extracting each column in the 2D array as a separate 1D array because I need to do calculations on them separately? 

 


The second Function on the Array Palette is called "Index Array".  By wiring an index into the first index, you can "pull out" the selected row.  If you click on the Help for this Function (or remember how it works from the LabVIEW Array Tutorials), you will see you can "pull down" and uncover a second Index that, if wired, will "pull out" the second "index-ed" element, i.e. the selected column.

 

I am deliberately not providing Block Diagrams for you, but am trying to get you to try some of these elementary functions yourself, learn how to use LabVIEW Help to learn how functions work, and create your own "solution" to your problem.  You'll learn and understand much better that way.

 

Bob Schor

Message 8 of 14
(1,663 Views)

@LindaLula wrote:

Hi Bob_Schor,

My next question is then how would you go about extracting each column in the 2D array as a separate 1D array because I need to do calculations on them separately? 


Did you even read my first answer above? This exact question was already answered right there. 😄


LabVIEW Champion. It all comes together in GCentral GCentral
What does "Engineering Redefined" mean??
0 Kudos
Message 9 of 14
(1,644 Views)

Maybe you should take a length of all the dimensions.  You may find that one of the three dimensions only has a single element; thereby making it equivalent to a 2-D array.

Help the Community (and future reviewers) by marking posts as follows:
If it helped - KUDOS
If it answers the issue - SOLUTION
0 Kudos
Message 10 of 14
(1,603 Views)