LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

MATLAB style 'sort' function

There is a function in MATLAB called 'sort', which spits out a sorted array
as well as the indices of the sorted array. The 'sort' function in LabView
only spits out the sorted array. I'd like to have the indices of the sorted
array so that I can sort other arrays and matrices similarly.

Thank,

Peter
0 Kudos
Message 1 of 7
(3,804 Views)
Peter,

You could create another column in your array that has the original index
numbers... then, use the multi-dimensional sort example from the NI
Development Library.

http://zone.ni.com/devzone/explprog.nsf/6c163603265406328625682a006ed37d/ba0
df5f844ff042e422565ec0046997a?OpenDocument

Bill

Peter T wrote in message news:3d0fcc0b@newsgroups....
> There is a function in MATLAB called 'sort', which spits out a sorted
array
> as well as the indices of the sorted array. The 'sort' function in
LabView
> only spits out the sorted array. I'd like to have the indices of the
sorted
> array so that I can sort other arrays and matrices similarly.
>
> Thank,
>
> Peter
>
>
0 Kudos
Message 2 of 7
(3,804 Views)
I ended up using a textbook called 'Numerical Recipes', which has an
efficient algorithm, written in FORTRAN. I translated to G and the routine
works well. When I configured the 2D Sort example to spit out the sorting
indices, it took hundreds of times longer to run than the one I translated.

Peter






[Attachment Heap Sort.vi, see below]
Message 3 of 7
(3,804 Views)

another way of doing this is by sorting a 1D cluster.

 

  The sorting of a bundle works on the first element within the cluster but the information between cluster elemnts remains the same.  This is a really usefull tool for many tricks within LabVIEW.

 

Message Edited by craigc on 09--03-2010 03:18 PM
LabVIEW 2012
Message 4 of 7
(3,395 Views)
Dont know how i managed to drag up an 8 yr old thread from the front page of the forum.  Was under the top kudo'd posts of the day :s
LabVIEW 2012
0 Kudos
Message 5 of 7
(3,368 Views)

craigc wrote:
Dont know how i managed to drag up an 8 yr old thread from the front page of the forum.  Was under the top kudo'd posts of the day :s

 

Well, it may be an old thread, but you did give good advice.

It probably saved some unnecessary Rube Goldberg code.

Array sorting can get very expensive, very quickly if it isnt done well

 

Cory K
0 Kudos
Message 6 of 7
(3,364 Views)
A month or so ago I generated some statistics on the forum, one of the things I look at was the longest time between post and accepted solution.  If the OP comes back (seems to visit, hasn't posted in 5+ years), he could mark this as a solution and we will have a new leader for the 'Patience is a Virtue' thread.  Smiley Very Happy
Message 7 of 7
(3,353 Views)