LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

rearrange 2 d array into ascending order

Hi,

 

i have a 2d array with the first column being a channel number for a thermocouple (15 thermocouples , 0-F) and the secound column being the data for that thermocouple. i am trying to rearrange the Array so that the first  'n' amount of rows is channel 0 and then the next rows are channnel 1 etc all with there corresponding data.

 

all i have been able to do so far is to arrange the channels in ascedning order but doing so it has alsos aranged the data in ascedning order so when i plot the data for channels 0 on a graph it plots it as a linear line . is there any way of just arranging the rows by ascedning order using the Channel column as the raference to arrange?

 

 

0 Kudos
Message 1 of 8
(3,919 Views)
0 Kudos
Message 2 of 8
(3,898 Views)

How about this:

Sort 2D Array of strings.png

 

 

George Zou
Message 3 of 8
(3,897 Views)

Thanks for the replys,

 

i have created the code that you had shown and it is arranging the data in not just asceding order of the first column but alsothe second column.


you can see from the orignal data that the first occurence of channel 0 is in the second row, its data is F32. F32 should be a the top of the newly arrange data, but as it is arranging both by ascending order it is in the 98th row.

 

ive attached a vi of the dta im receiving

Message 4 of 8
(3,865 Views)

From the help file for the Sort 1D Array function:


If array is an array of clusters, the function sorts the elements by comparing the first elements. If the first elements match, the function compares the second and subsequent elements.


 

 

This is expected behavior.

 

To do what you requires more complicated tracking of positions of data in the array.  I do not have time now to put together an example.

 

Lynn

0 Kudos
Message 5 of 8
(3,841 Views)
0 Kudos
Message 6 of 8
(3,832 Views)

@l_m_s wrote:

 

i have created the code that you had shown and it is arranging the data in not just asceding order of the first column but alsothe second column.


The problem is that you are dragging the entire array through the sorting mechansims, while it should only see the first column. If you do it as follows, the rows are sorted by the first column, leaving the second column in original order (note that the second cluster element is array index in the original array, so it is sorted by that if duplicates in the first column occur. That's apparently what you want.

 

(Note that the the overall logic is probably similar to what  AYanez posted above, it just uses much less code and is more efficient. (see my signature! :D)

 

See if this works for you. Good luck!

 

 

I also strongly suggest that you don't parallelize these tiny loops. The bulk of execution time is spent  sorting, and rattling through  simple arrays is ~infinitely fast. Most likely the parallelization overhead is high in comparison and you'll not gain anything. It might actually slow you down. Note that the sorting itself if much faster in my code, because the cluster structure is much simpler.

.

Download All
Message 7 of 8
(3,816 Views)

Hi All,

 

I know this is just another variation on the same theme but this example worked well for me in one of my projects.

 

Best Regards,

 

Chris

National Instruments - Tech Support
0 Kudos
Message 8 of 8
(3,762 Views)