Output array with label AFTER sort?

Forums ProRealTime English forum ProBuilder support Output array with label AFTER sort?

Currently, there are 0 users and 1 guest visiting this topic.
View all attachments
Viewing 12 posts - 1 through 12 (of 12 total)
  • #184936 Report

    Hi

    I think I know the answer to this already but is it possible to associate a label with array entries so that they stay in the correct place after an arraysort?

    In the hypothetical example below, it works until I sort the array and then you would lose the label order obviously.

    Is there a way this could be achieved?

    Thanks

    Rob

    #184939 Report

    You need to use two arrays, 1 for data and 1 for labels, then sort them using custom code (such as bubble sort), provided arrays arrays are not too large.

     

    1 user thanked author for this post.
    #185303 Report

    Hi

    I have bubble sorted my array and realised I have duplicates to remove which I have kind of done by using a second array.

    However, I would like to use the same array but I end up with ‘n/a’ displaying (after drawtext) where the duplicates have been removed.

    Could someone please help? Been going round in circles!

    Thanks, Rob

     

    #185312 Report

    It’s because I and J retain different values.

    It may happen that in line 7 $temp[i] has not yet been created,

     

    #185314 Report

    Thanks Roberto.

    Is it possible to just use the same array, I would like to try example 2 of this pseudo code but have struggled to translate it in ProBuilder?

    https://www.codesdope.com/blog/article/remove-duplicate-elements-from-sorted-array/

    Thanks again.

     

     

    #185332 Report

    This is the Bubble Sort snippet:

    This an indicator (example) to be added ON the price chart:

    Attachments:
    1 user thanked author for this post.
    #185338 Report

    Perfect!

    Thank you.

    #185347 Report

    Sorry, I just realized there’s an error in my pic and in the example (it’s an error concerning display only, the sorting code is correct). This is correct:

    the error was in DRAWTEXT. The second block prints the correct (sorted) data, but the wrong labels (as they shall NOT sorted, as they follow the sorted data).

     

    Attachments:
    1 user thanked author for this post.
    #185367 Report

    Thanks, is it possible to remove duplicates after the array/s have been sorted?

    I’m guessing the non duplicates may need to go into a new array or can we reset the original array and then copy the non dupliate values in? This is the bit I’m struggling with. I thought I was there earlier and then tried it on some different values and my code clearly doesn’t work.

    Thanks again. Rob

    #185443 Report

    This version removes duplicates (I created two new, separate, arrays):

    1 user thanked author for this post.
    #185461 Report

    Thanks so much Roberto!

    I’ve just wasted the morning doing it old school without arrays and then I see this!

    Hopefully it will get added to the code snippet spreadsheet so others can benefit.

    Really appreciate this a lot.

    Thank you.

     

     

    1 user thanked author for this post.
    #185530 Report

    Link to code above added as Log 313 here …

    Snippet Link Library

    1 user thanked author for this post.
Viewing 12 posts - 1 through 12 (of 12 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login