LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to convert 2D array into different structure

I have difficulty to convert a 2D array into different structure based on the first column. The first column is like
 
 1
3
4
6
9
 
I want sort this 2d array to be like
1
2
3
4
5
6
7
8
9
 
The other column will be sorted as well, but leave blank cell as "empty string constant"
 
Please help
Liming
0 Kudos
Message 1 of 7
(3,285 Views)
I have attached a vi that sorts a 2D array.  You must tell it what column you want to sort on and if you want to sort in ascending or descending order.  Whichever column is chosen to be sorted, the elements in the other columns will follow the sorted element.  Like this:
 
Before sort:
2  4  6
1  3  5
4  6  8
3  2  1
 
After sort on column 0:
1  3  5
2  4  6
3  2  1
4  6  8
 
 
- tbob

Inventor of the WORM Global
Message 2 of 7
(3,273 Views)

Sorry I did not make my question clear before.

Your sort 2D program works. I want to do further.

For instance:

Before sort:

2 4 6

4 1 1

5 3 8

7 2 3

After sort (more rows are added):

0 0 0

1 0 0

2 4 6

3 0 0

4 1 1

5 3 8

6 0 0

7  2 3

That means your sort vi can sort array by the first column. Then I need to add more rows if two adjacent  number is not continuous. Eventually I want the first column is like:

1

2

3

4

5

6

7

0 Kudos
Message 3 of 7
(3,265 Views)
It looks like you want to pad zeroes for the non-contiguous numbers in the first column after sorting.  This can get a little complex.  Sorry I don't have time to work on it now, perhaps tomorrow.  You should try.  Find the max value of the elements in the first column.  Wire this value to a For Loop counter input.  Use the i of the for loop to compare each array element in first column.  If not found, insert the i followed by zeroes into an array.  you will need a shift register to form the output array.  If the number is found, insert the entire row into the array.  Try it yourself and ask for help if you run into problems.
- tbob

Inventor of the WORM Global
0 Kudos
Message 4 of 7
(3,262 Views)
Just a remark. The attached OpenG Sort 2D array, which basically uses the same trick (I didn't try to identify the critical step), is about 6 times more rapid on my PC (sort a 1000x50 array in 50ms instead of 300 ms). I just made a slight modification to allow for case insensitive sorts.
 
You should have a look at http://www.OpenG.org, where you can download some really nice tools. And it's free !
Chilly Charly    (aka CC)
Message 5 of 7
(3,252 Views)

Thanks. I did it per your instruction. Only one thing I did not feel comfortable. I used a local varable of Array in For loop. I can also use a Local Variable of Array in to do the same thing. That is my old question, I meet it today. Which is better, what is the difference? Is any other option to bring Array in to inside of Loop.

Thanks

0 Kudos
Message 6 of 7
(3,251 Views)
You don't need to use any local variable or property node. Just wire directly the array. See the corrected vi.
Chilly Charly    (aka CC)
Message 7 of 7
(3,246 Views)