05-31-2014 08:29 PM
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?
05-31-2014 10:10 PM
The code of this thread should help you: http://forums.ni.com/t5/LabVIEW/How-to-convert-2D-array-into-different-structure/m-p/25622
05-31-2014 10:11 PM
How about this:
06-01-2014 05:15 AM
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
06-01-2014 10:12 AM
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
06-01-2014 11:32 AM
Try this.
06-01-2014 12:10 PM - edited 06-01-2014 12:23 PM
@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.
.
06-02-2014 04:42 AM
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