LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Multiple 1d arrays from 2 d array

Hello,

 

I have a function that opens a .csv file using 'read from spreadsheet file." The result is a 2D array of channel numbers (for a switch system). The issue is that since arrays are assumed to be the same number of rows and columns, there are "empty" elements in some cases. If I read an empty element into the swith system, it wont know what to do. 

 

How can I get my code to "skip" over those empty elements?

 

I tried to get over this by taking the 2 dimensional array and turning it into 1D arrays. However, this doesn't work! When I index the array to extract one column, then do a "reshape" array to a 7x1 (1 d array)... it still spits out a 2d array!! why does it do that? I thought reshape array allows you to change the dimensions of the array. No matter what I do, I keep getting 2-d array data out. 

0 Kudos
Message 1 of 13
(3,970 Views)

If you just Index Array with an index only wired up to the column input, then you get a 1D array.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 2 of 13
(3,967 Views)

Thanks! 

 

I was able to get the first column of the original 2d array as a 1d array. I would like to be able to do this iterativley until all the columns of the 2d array are asserted into their own unique 1 d arrays. How can I do this and still have all the 1 d arrays grouped together... like a cluster of 1 d arrays? 

 

I tried feeding this into a For loop. Please see attached code. 

0 Kudos
Message 3 of 13
(3,960 Views)

Snow_In_Tehran wrote:

The issue is that since arrays are assumed to be the same number of rows and columns, there are "empty" elements in some cases. If I read an empty element into the swith system, it wont know what to do. 


The number of rows can be different from the number of colums. However all rows are the same lenght. LabVIEW does not support ragged arrays.

 

How do you read the file?If you read it as "numbers", empty will show up as zero. You might want to read it as strings and discard empty strings before comverting to numerics.

 


@Snow_In_Tehran wrote:

How can I get my code to "skip" over those empty elements?


Are they always at the end of the row or can they be anywhere? Are all valid elements adjacent starting with the first element?

 


Snow_In_Tehran wrote:

I tried to get over this by taking the 2 dimensional array and turning it into 1D arrays. However, this doesn't work! When I index the array to extract one column, then do a "reshape" array to a 7x1 (1 d array)... it still spits out a 2d array!! why does it do that? I thought reshape array allows you to change the dimensions of the array. No matter what I do, I keep getting 2-d array data out. 


To reshape into a 1D array, you would need to resize the reshape function to only show one size input. However, if you use index array on a 2D array, you should get a 1D array directly (unless you wire both indices).

 

It would be much easier to help you if you would show some of your code.

 

0 Kudos
Message 4 of 13
(3,956 Views)

Here's how you would build an array of clusters, each containing a 1D array derived from a column. Each element can have an array of different lenght.

Message 5 of 13
(3,947 Views)

Can you also post your CSV file?  That would help us a lot in figuring out what it exactly is that you are trying to do.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 6 of 13
(3,945 Views)

Please reference attached code. I see now that the index array function will give me a 1D array if I leave the row terminal unwired and wire the column terminal... which is exactly what I want:. I basically want each of the columns of the 2d array to be its own 1 d array.

 

However, how can I do this iteratively?  If you see the included code, I figured I'd use the iteration value in the "for-loop" to index the sucessive columns. so as the iteration steps through 0....n, I will get 1 d arrays for each of those values. However, I am not getting correct results. 

 

My idea is to ultimatley turn all the 2-D array columns into their own 1 D arrays... then filter out the empty values in each 1D array... then feed each filtered 1D array into myswitching system. I'm not sure how to actually implement this. FYI, I'm reading this .csv file in string form. 

 

If you see my second attachment, its my overall code. The "DMM +" array is fine since its already 1d. Its the "DMM -" array which causes trouble because of these empty values. 

 

Thaank you

Download All
0 Kudos
Message 7 of 13
(3,943 Views)

Hello, 

 

See the attached CSV file. THis is for an "isolation test" . In other words, every pin tested to every other pin. Hence, the decreasing number of pins (as columns) in the "DMM -" file.  

Download All
0 Kudos
Message 8 of 13
(3,941 Views)

Just use my code but instead of bundling, process the trimmed column inside the loop directly.

Message 9 of 13
(3,940 Views)

Thanks! I'm going to use your code but simply process each trimmed column one-by-one somehow. 

0 Kudos
Message 10 of 13
(3,933 Views)