I need sorting VI that returns the sorted array element's positions in the unsorted array

I need a VI that will very quickly (n log n) sort a 1D array of doubles.  This VI should not only output the sorted array, but for each of the sorted array elements, it should also output that sorted array element's position in the unsorted array.  So for example if the input array were:
unsorted_array
4.1
2.3
7.0
5.6
10.2
Then the output arrays would be:
sorted_array
2.3
4.1
5.6
7.0
10.2
indices_array
1 (the value 2.3 is located at position 1 in the unsorted_array)
0 (the value 4.1 is located at position 0 in the unsorted_array)
3 (the value 5.6 is located at position 3 in the unsorted_array)
2 (the value 7.0 is located at position 2 in the unsorted_array)
4 (the value 10.2 is located at position 4 in the unsorted_array)
This way I could generate the sorted_array using just the indices_array and the unsorted_array.  Has anyone written a nifty piece of code to do this?  I did some research on (n log n) sorting algorithms but most of them use recursion which I don't know how to do in LabVIEW.  It would also be nice to have an algorithm like this that could sort an array of strings.
cheers,
Richard

Try something like the attached example (LabVIEW 7.0). I think it does what you need.
(To understand the code, it is important to know that arrays of clusters are sorted by the first element in the cluster).
Sort array itself sorts also array of strings, so you could just substitute, keeping the rest of the code the same.
Sort array uses a variation of quicksort, so it should have about NlogN complexity.
(If you think you only need the array of indices to later generate the sorted array, it does not make much sense to even do it. To get the indices, you need to sort the array anyway. You should just sort the plain array directly.
Message Edited by altenbach on 07-13-2005 03:47 PM
LabVIEW Champion . Do more with less code and in less time .
Attachments:
SortAndIndex.vi ‏26 KB

Similar Messages

  • I need a query that returns the average amount of characters for a text colum in MS SQL.

    I need a query that returns the average amount of characters
    for a text colum in MS SQL.
    Could someone show me how?

    Sorted, i need the
    DATALENGTH
    function

  • I need a query that selects the amount of records for each day in a table.

    I need a query that selects the amount of records for each
    day in a table.
    Eg the result would be:
    date 1 14
    date 2 3
    etc
    Any ideas?

    sorted:
    SELECT count([commentID]),convert(varchar, dateAdded, 112)
    FROM COMMENTSgroup by convert(varchar, dateAdded,
    112)

  • What is the Function MOdule that returns the fields in database table order

    Hello Folks
      I have a dynamic internal table with fields ( which are not in order). I want to display them in the order of which they are present in the database table? Is there any function module that returns the fields in database order?
    FAQ. Please search before posting your question.
    Edited by: Suhas Saha on Oct 10, 2011 10:19 PM

    Hi,
    You can use this BAPI.
    <b>BAPI_SALESORDER_GETLIST</b>
    Reward if useful.
    Regards,
    Vimal

  • I forgot my Apple ID password. and I tried to rest it but I don't get a reset email to change the password. What do I need to do to return the account. (I need the specified account because I bought apps with it.)

    I forgot my Apple ID password. and I tried to rest it but I don't get a reset email to change the password. What do I need to do to return the account. (I need the specified account because I bought apps with it.)

    The Best Alternatives for Security Questions and Rescue Mail
        a. Send Apple an email request at: Apple - Support - iTunes Store - Contact Us.
        b. Call Apple Support in your country: Customer Service: Contact Apple support.
        c. Rescue email address and how to reset Apple ID security questions.

  • I need a script that copies the filename into the file

    I need a script that copies the filename into 4th column of each line in the text doc file.
    I have over 2000 different file names each containing 6 columns and ~50-100 rows.
    I can do this manually using this script:
    awk '{print $1"\t"$2"t\"$3"\t <name> \t"$6}'
    But I would like an automation command or script. Is there any command that I can use instead of <name> that will copy the filename into the column?
    Thanks
    Monica

    Oops, I forgot the redirect to a file. It's not a good idea to edit files in place. A script could fail and you're left with at least one file ruined. It's better to create new files then delete the old files.
    for file in *; do
        while read col1 col2 col3 col4 col5 col6; do              
            printf "%s\t%s\t%s\t%s\t%s\n" $col1 $col2 $col3 $file $col6
        done < $file > n$file
    done
    You could narrow the files listed such as
    for file in *.tsv
    and redirect the new files to another directory. Such as
    done < $file > /absolute/path/to/directory/$file

  • BAPI OR RFC THAT RETURNS THE VALUE TABLE CONTENTS THAT IS SPECIFIED IN DOM

    HI ALL,
    i have requirement of BAPI  or RFC that returns the value table contants(text table) in CRM..
    for ex:
      if i  pass the dataelement or domain or checktable as input parameter,could i get the contents of its text table associated with it....
    please if there is way help me on this..
    thanks and regards,
      goutham,

    Check these FM
    RFC_READ_TABLE
    RFC_GET_TABLE_ENTRIES

  • How come my macbook air has so little space. I deleted everything that I don't need and everything that has the most space I'm told NOT to delete. Everything I find is in either KB or very low MB.

    How come my macbook air has so little space. I deleted everything that I don't need and everything that has the most space I'm told NOT to delete. Everything I find is in either KB or very low MB.

    Check what is in your SSD/ storage on your macbook  Apple Icon >   about this mac > more info >  STORAGE tab on top
    recommend handy useful APPS such as :
    Disk Expert
    https://itunes.apple.com/us/app/disk-expert/id488920185?mt=12
    Disk Map
    https://itunes.apple.com/us/app/disk-map/id715464874?mt=12
    dont need them, but theyre very useful.
    also the best is DAISY DISK
    https://itunes.apple.com/app/daisydisk/id411643860?mt=12&ign-mpt=uo%3D4
    See here for answer about the OTHER which is taking up space:
    http://pondini.org/TM/30.html
    and here:
    http://pondini.org/OSX/DiskSpace.html
    See Kappys excellent note on the rest of “other” files taking up your space:
    What is "Other" and What Can I Do About It?
    see here:
    Your Solid State Drive and having enough space inside your Macbook Air & Pro
    Solid State Drive usage premise, or the “more space / upgrade SSD” question
    There have been questions posed and positions taken by many people who are trying to use their Macbook Air or Pro’s solid state drive (SSD) as a mass media storage device, for either pictures, videos, massive music collections or all three combined; but this should not be the working premise of a ‘limited’ SSD and its use.
    In which, it’s the case of those users with either 128GB, 256GB, or even 512GB of internal SSD space, that have or are running “out of space”, that questions are raised. The immediate premise of some users can sometimes be “(how to / if) upgrading my SSD” when in fact in nearly all instances another approach is the logical and sensible one that needs to be looked into and exercised.
    Any Macbook containing a SSD should be idealized as a ‘working platform’ notebook containing all your applications, documents, and weekly or bi-weekly necessary files. All collections of media files such as pictures, music, and videos, unless directly needed should be kept off the notebook and on an external hard drive or likewise. While the ‘working platform’ premise is also the case with larger internal conventional hard drives of 1TB+, its implementation isn't as critical except in terms of data protection.
    Realistically, you should at most coordinate roughly 20 to 25% of your total SSD space to all audio-video personal use media (picture / music / video collections), leaving the remaining amount on an external HD.
    Nobody should consider any notebook a data storage device at any time under any circumstance, rather a data creation, sending, and manipulation device; and in the case of a SSD, this is more important for purposes of having sufficient working space on the SSD and reducing SSD ‘bloat’ in which cases someone is wrongly attempting to use the SSD space as a large media storage nexus.
    The rare exception to the collective usage and premise of SSD use in which a much larger SSD is truly needed are for those in video and photography professions that require both the extremely fast speeds of the SSD and the onboard storage for large and or many video and photography files. However this also falls under the premise of a ‘working platform’ for such peoples rather than the intent of many who are using the SSD as passive and static data storage for media files very infrequently needed or accessed.
    All on-notebook data collections should be logically approached as to necessity, and evaluated as to whether it is active or passive data that likely doesn’t need to be on the notebook, allocations of space-percentages to as-needed work and use, apportioning space for your entertainment media, and questioning whether it should it be on the notebook for more than short-term consumption.
    Considerations should be made in the mind of any user in differentiating the necessary system data (System hub) comprising the Mac OSX, applications, necessary documents that both must and should be on your internal SSD, and that of the users personal data (Data hub) comprising created files, pictures, music, videos, PDF files, data created or being created and otherwise, that likely unless being used soon or often should be parked on an external hard drive for consumption, or temporarily loading onto the internal SSD.
    You both can and should purchase whichever SSD size you need or see fit, but even in the case of the largest of SSD, unless use-considerations are made, and SSD spaces are allocated as should be the case indicated above, one can easily and immediately run into this quandary of “needing more internal SSD space”, in which instance a different approach in usage must then be implemented.
    However it is almost always the case, that such large media files are wanted to be stored internally rather than actually needed, in which case the external HD is both prudent as well as necessary. Additionally costs per MB are infinitely less on an external HD than an internal SSD in any consideration of data expansion needs.
    A Professional Example
    In the case of a Macbook Air or Macbook Pro Retina with ‘limited’ storage on the SSD, this distinction becomes more important in that in an ever rapidly increasing file-size world, you keep vital large media files, pics, video, PDF collections, music off your SSD and archived on external storage, for sake of the necessary room for your system to have free space to operate, store future applications and general workspace. 
    You should also never be put in the position of considering “deleting things” on your Macbook SSD in order to ‘make space’. This is especially what your external HD is for.
    Professionals who create and import very large amounts of data have almost no change in the available space on their notebooks internal SSD because they are constantly archiving data to arrays of external or networked HD.
    Or in the case of the consumer this means you keep folders for large imported or created data and you ritually offload and archive this data for safekeeping, not only to safeguard the data in case your Macbook has a SSD crash, or gets stolen, but importantly in keeping the ‘breathing room’ open for your notebook to operate, expand, create files, add applications, for your APPS to create temp files, and for general operation.
    Slim USB3 1TB external hard drive
    External Hard Drives
    External hard drives are both extremely cheap and regardless of the size of your internal SSD (or even internal hard drive if the case), you need an external hard drive with your SSD equipped Macbook for several reasons:
    1. Data backup and protection.
    2. Redundancy for important data.
    3. Necessitated ideal space for large media files for collections of pictures, videos, and music etc.
    While ever changing in price, typical portable 2.5” external hard drives in USB3 run roughly $65 for 1TB or $120 for 2TB small portable USB3 hard drives. Such drives range in thickness between 5mm and 15mm, with recent improvements in storage of 500GB drives in 5mm profiles.
    There is almost no premise in which a small 12mm thick 1 Terabyte USB hard drive cannot be taken along with any Macbook as an external large storage extension inside any Macbook carry case or pouch. Typically such external HD profiles are not much bigger than a deck of cards.
    External hard drives are a foregone necessity for purchase with any Macbook for at the very least Time Machine backups, data redundancies, and ideally for large media storage.

  • BAPI that returns the PurchasingOrg of given user.

    Hi all,
    I'm trying to find BAPI that returns the PurchasingOrg of given user.
    Any help will be very appreciated.
    Thanks,
    DannyL

    >
    Danny Leviev wrote:
    > Hi all,
    >
    > I'm trying to find BAPI that returns the PurchasingOrg of given user.
    >
    > Any help will be very appreciated.
    >
    > Thanks,
    >
    > DannyL
    Hi dear,
    Can u explin in deatails what exactly you are looking for??

  • I submitted my information to receive a replacement 1st generation nano but somehow did not notice what steps I needed to take to return the Ipod to Apple. What needs to be done after submitting the serial number information online?

    I submitted my information to receive a replacement 1st generation nano but somehow did not notice what steps I needed to take to return the Ipod to Apple. What needs to be done after submitting the serial number information online in order to obtain a replacement?

    They're supposed to send you a box with shipping instructions which you then use to send them your 1st generation iPod, however, I've been waiting a month for my box and can't figure out why I have not received it

  • Available webservice/tool that returns the physical qry from logical qry?

    Is there any obiee webservice or program that returns the physical query by receiving the logical query as a parameter ?
    What we are looking for is to have a "process" that use the logic that bi server has to resolve the reports using the metadata (rpd) to derive the physical query.
    It should be like the logic that is behind the "issue direct sql" function. But instead of pasting the logical query into the text box we will be passing it as a parameter in a custom process.
    Many thanks,
    Georgina

    800 by 800 pixel file @ 300 DPI:
    Guide @ random position:
    800 by 800 pixel file @ 300 DPI:
    Guide @ 40,341 mm
    One selection drawn from the left, one from the right.
    The border of the selection should be on the same left-right-position, but differs about one pixel (these are all zoomed in).

  • I need a sql statment that return the platform on which oracle is installed

    hi all
    in Oracle 10g there is a column in v$database names platform_name that contain the platform name on which oracle is installed.
    do you know how can I check it in oracle 9i/9i ?

    And just to note:
    Sandeep's solution only works if your user has access to the V$DATABASE view which most standard users won't.
    Kamal's solution will work with most users providing they haven't had permission taken away from them in regards the dbms_utility package.

  • Need a function that return multiple rows

    Hi,
    I need a function that should return output of this query
    SELECT b.branding_code, c.name_desc
    FROM
    development.brandings b, godot.company c
    WHERE b.company_id = c.company_id;
    This above function return 30 rows and I am not giving any input
    Function using cursor,pipeline
    Please help
    Edited by: 1008783 on Jun 6, 2013 6:40 AM

    Hi,
    1008783 wrote:
    Hi
    Table A:
    Development schema
    branding_code,company_id
    Table B:
    Gogot schema
    name_desc,...Those aren't CREATE TABLE and INSERT statements. Post something that the people who want to help you can run on their own systems to re-create the problem and test their ideas.
    o/p:
    branding_code,name_desc
    I should return these column as o/p, no i/pA query will do that. There's no need for a function.
    There are good reasons for wanting a functin. If you have one, say what it is. Explain how you plan to use the function.
    Have you tried writing a function? Post your code. What specific problems did you have?

  • Looking for a function that returns the currently opened document type

    Dear SAP gurus
    I have a user exit for transaction VA02. In VA02, when I click on button (Item details-configuration),
    it launches a URL in a browser. I am asked to add to the URL, values like Document Type, Document Number
    and Line Item Number.
    I can get Document Number and Line Item Number from the presently opened Sales Document by using the standard Function 'CUCB_GET_OWNER_OF_CFG'.
    However, I am not able get the value of Document Type. Is there any function that will give me
    the value of the Document type of the present document that is open.
    Any feedback/Suggestion will be highly appreciated.
    Thanks
    Ram

    If you're in a VA02 user exit, the document type should be in VBAK-AUART, if I remember the field name correctly.  I would think that ANYWHERE in VA02, that field will be available to you.
    If you want the text of the document type, forward navigate from vbak-auart data element to the domain and look at the values...there'll be a config (T) table (and you may need to add T to the end to get the associated text table) that describes the document type in your system's language,  like:
    E OR   Order
    or something like that...  Sorry, in my installation, we don't use the logistics modules, so I'm writing from memory.

  • Is there any function that returns the latest DDL statement

    can anyone tell me if there is any FUNCTION that returns latest DDL statement performed in a schema.
    OR
    if there is any TABLE that will be populated with latest
    DDL statement in schema.
    THANK YOU.

    The table all_objects (and/or dba_objects) contains a column called last_ddl_time. Thus, a query like
    scott@jcave > SELECT max(last_ddl_time)
      2  FROM all_objects
      3 WHERE owner = 'SCOTT';
    MAX(LAST_DDL_TI
    28-NOV-03will tell you the last time any object owned by SCOTT had DDL issued against it.
    Justin
    Distributed Database Consulting, Inc.
    www.ddbcinc.com/askDDBC

Maybe you are looking for

  • Web graphic is not displayed the first time

    Hi all I have a strange issue with some users.  The first time that they run the qry in the web, the chart is not diplayed, only is displayed a big "X" and the error msg is the msg below; but when they refresh, the chart is displayed ok. How can I so

  • Warning message on MRP view

    Hi consultants, I have a material that is specified as "External Procurement" Material.   It is because it's a Subcon material.  In line with this, a production version is maintained due to some business process requirement, which the system allows. 

  • Leave Approval Notification

    Hi Experts, i have a requirement in which i have to change the E-Mail notification addresses as per the employee Personal Area once the leave is approved. Once the leave is approved the notification should be sent to respective HR Teams . As example:

  • No black printing

    I have a photsmart 3110 that doesn't want to print black. It will print any other colour except black. Black and white documents are blank peices of paper. Sometimes we get a 0xc19a0013 error, but thats just related to the black ink. I have installed

  • Application module creation failed

    Can someone please help me? My data form (which runs fine through jdeveloper) is failing when I try to run it with an applet. This is what I get: DAC-405: SessionInfo: Application module creation failed; className: productionApp java.rmi.Remote I've