From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Sort array with equal elements

Hi, I'm a new one.

I have a problem to sort 2d array with equal elements (it has 5000000 of elements from 1-255) for example:

 

1 2 1 1 3 4 5 5 6 1 2 3 (value from 1-255)

2 2 1 1 3 3 3 3 4 4 4 1 (value from 1-255)

 

And I need make array or matrix 255 rows vs 255 colomns, and count how many equal elements for example:

 

  1  2 3 4 5 6

1 0 1 0 1 0 0

2 0 1 0 1 0 0

3 1 0 1 0 0 0 

4 0 0 1 0 0 0

5 0 0 2 0 0 0

6 0 0 0 1 0 0

 

I'll be happy if someone could help me

0 Kudos
Message 1 of 11
(3,752 Views)

Not sure I understand your problem / requirement, can you explain it a bit better please? Also post any code you have already tried.


CLA CTAChampionI'm attending the GLA Summit!
Subscribe to the Test Automation user group: UK Test Automation Group
0 Kudos
Message 2 of 11
(3,734 Views)

Hi Bloodhorror,

 

when you want to sort a 2D array you should note by which order you want to sort: by column or by row? Which column (or row) will determine the sorting order?

 

How do you want to "make the 255×255 array"? By random numbers? Use two FOR loops…

 

Do you want to count equal numbers for each row, each cloumn or the whole array?

Usually this is called "histogram" and LabVIEW offers ready-to-use functions for that purpose!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 3 of 11
(3,733 Views)

I understand that it's very complicated explain.

I build 2d array from two 1darray each of them has values 1-255. So right now i must constract array or matrix 255x255 where must calculat how many times value from (1-255) for one array in another array and write this sum for each value 1-255. I try to show it

 

1 2                         so I need array 3x3; for first row for value 1 I have two times value 3 and one time value 2

2 2                                                                                    2 I have two times value 1 and one time value 2 and one time value 3

3 2                                                                                    3 I have two times value 2 and one time value 3 

3 2              so my result matrix will be      1   2  3

3 3                                                       1  0  1  2

2 3                                                       2  2  1  1

2 1                                                       3  0  2  3

2 1

1 3

1 3

Maybe its more clear

0 Kudos
Message 4 of 11
(3,724 Views)

Hi bloodhorror,

 

- build an 1D array of cluster from your two 1D arrays.

- Sort that cluster array.

- split that array two pick the parts with equal first cluster element

- from the parts you build an array of the 2nd cluster element and calculate an histogram of

- repeat 3rd and 4th step for each 1st cluster element

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 11
(3,720 Views)

Or just do it this way

 

sort.png


CLA CTAChampionI'm attending the GLA Summit!
Subscribe to the Test Automation user group: UK Test Automation Group
0 Kudos
Message 6 of 11
(3,705 Views)

Thanks for your help but maybe I do something wrong because Vi not working

0 Kudos
Message 7 of 11
(3,694 Views)

You have not wired the array in to the place element structure. Its just wired through.


CLA CTAChampionI'm attending the GLA Summit!
Subscribe to the Test Automation user group: UK Test Automation Group
0 Kudos
Message 8 of 11
(3,692 Views)

Many Many thanks

0 Kudos
Message 9 of 11
(3,670 Views)

can you provide the final VI with no errors .....

0 Kudos
Message 10 of 11
(3,640 Views)