03-01-2017 10:32 AM
I have a 2D array in the form as followed
1,1
1,3
2,1
2,2
2,3
3,1
4,1
4,2
5,1
5,5
I want to sort it (based on the second column) only when the element in the first column is even, for example, new array should be:
1,1
1,3
2,3
2,2
2,1
3,1
4,2
4,1
5,1
5,5
I have tried many days but failed. Thank you so much!
Solved! Go to Solution.
03-01-2017 12:28 PM
There are probably several different ways to attack this.
Here is the way I would try first.
It is always a 2-D array that has just 2 columns?
Take the array and iterate through it row by row. Build a cluster that contains the column 0 value, the column 1, value. If yo do this with an auto-indexing For Loop, you'll wind up with a 1-D array of clusters.
Sort that 1-D array of clusters. (one question though, it looks like your "sorted" array has the even numbers in reverse order. That might complicate the sorting process, but there could be other ways around that.
With the Sorted 1-D array, go through element by element. If the first item in the cluster is odd, just build the elements back into a 1-D array. If that element is even, then take the row from the original, unsorted array. Do that in a For Loop and you'll have a 2-D array of original odd numbers, and sorted event numbers.
03-01-2017 01:06 PM
Something like that I guess...
That property nodes were Array in local vars at different steps to compare side by side... Snippet breaks them =( VI is correct
03-01-2017 01:37 PM
Alexander_Sobolev wrote:... Snippet breaks them =( VI is correct
Use the Code Capture Tool you can install from VI Package Manager. It doesn't break snippets the way the built-in VI snippet maker does.
03-02-2017 04:08 AM - edited 03-02-2017 04:09 AM