LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

2d array sort

Hi
 
I'm trying to sort each row in a 2d array according to the elements of a 1d array
 
my 1d array is composed of multible instances of intigers with range 0 < i < n-1
and could look like this for n=3
0
2
1
0
1
0
my 2d array might look like this
a a
b b
c c
d d
e e
f  f
 
I need to rearrange the 2d array so that each row be arranged with index the intiger in the 1d array that currently has the same index as that row  ie
the 1d array elements should become the indeces  for the rows of the 2d array. However, rows assigned with the same index should not be merged. once a row is assigned an index previously assigned to a different row then the previous rows index should increment.
the end result should look like that rows with the same assigned index from the 1d array are moved closer together in the 2d array
for the example above the resulting 2d array would be
 
a a
d d
f  f
c c
e e
b b
 
 i 've been on this almost 3 weeks now and cant seem to make it any ideas would be very helpful, if any questions let me know
 
Thanks
 
George
 
0 Kudos
Message 1 of 9
(6,841 Views)

Hi Giorgos

the easiest thing to do is to cluster each line of the 2D array with the appropriate value of the numeric array, then sort the resulting new array (if sort is used on a cluster, it always sorts the first element), then split the cluster again.

Good luck

Guenther

 

Message 2 of 9
(6,809 Views)
that should do it
 
thanks guenther
 
 
Giorgos
0 Kudos
Message 3 of 9
(6,779 Views)

Dear Guenther,

 

lately i ran into a similar problem and i used your way to sort my 1D-2D array but apparently there is a serious problem in my case. the sorting works fine, but this algorithm not only sorts the first 1D array but it also puts the second 2D array in order too; i mean in an ascending order. to make it easier to understand what i mean i attached my sample vi plus a screenshot.

 

sort.JPG

 

 

as you can see the output array starts with an 'a-a' pair instead leaving the order like 'd-d,a-a,b-b' for the corresponding 0s in the first array.

 

i wonder if it is possible to sort only the first 1D-2D array in a way that the resulting 2D array would look like the following in this case:

d-d

a-a

b-b

h-h

c-c

f-f

e-e

 

Thanks,

Attila

 

0 Kudos
Message 4 of 9
(5,168 Views)

Hi Attika,

 

you're right, if the first cluster elements are equal, then the sorting will proceed to the second element and so on.

If you want to prevent this, cluster your ID with an "uncritical" variable like an index and then use the index to sort the 2D array.

Example is attached.

 

Have fun

Guenther

sort2panel.PNG

 

 

Message 5 of 9
(5,157 Views)

Thank you!

This is exactly what i needed! You can't imagine how much you helped me! 🙂

 

0 Kudos
Message 6 of 9
(5,153 Views)

Hello everybody, I am new to Labview. I am trying to arrange the 2d data in decending order  according to numeric values but I am unable to getting decending orderd data, I want exacktly like Attika posted picture.Please can anybody help, here I am attaching my vi.

Thanks in advance.

0 Kudos
Message 7 of 9
(4,456 Views)

What do you want the output array to look like? Which column or row do you want to sort on?

 

Mike...


Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 8 of 9
(4,451 Views)

@GuentherS wrote:
 

Hi Giorgos

the easiest thing to do is to cluster each line of the 2D array with the appropriate value of the numeric array, then sort the resulting new array (if sort is used on a cluster, it always sorts the first element), then split the cluster again.

Good luck

Guenther

 


Simple but really tricky one. Very nice

-----

The best solution is the one you find it by yourself
0 Kudos
Message 9 of 9
(4,445 Views)