We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexSuggestions & BugsSoftware,  Documentation,  Website Suggestions › suggestion for sort() function ... X=sortIndex(A)
Page Index Toggle Pages: 1
suggestion for sort() function ... X=sortIndex(A) (Read 537 times)
suggestion for sort() function ... X=sortIndex(A)
Sep 11th, 2007, 11:43pm
 
I have a suggestion for an enhancement to the sort() function.

Presently, B = sort(A) returns a new array B
containing the sorted values from A, and leaving A unchanged.

In many instances, we want to know HOW the values from A got rearranged.

I program in MATLAB a lot, and one version of the sort function
looks like this:  [B X] = sort(A)
where X is an array of index values
B[0] = A[X[0]]
B[1] = A[X[1]]
B[2] = A[X[2]] and so on.

I suggest include this functionality in Processing.
One way would be to extend "sort" to support the following variation:
 X = sort(A,INDEX)
or else make a separate function "sortIndex"
 X = sortIndex(A)

I am not an expert in JAVA, but I wouldn't be surprised
if something equivalent to "sortIndex" already exists.

-- djones


Page Index Toggle Pages: 1