Remove repetitions from array

Hi
I would like to know how to remove repeitions from a 1D array. For example, AAANNNNDDDDKLL to ANDKL.
Also, what if the array is not sorted?
Arjun

I have used this one in the past.  But if anybody has a more memory effecient way to do it I would be happy to hear it.
Attachments:
RemoveDups.vi ‏8 KB

Similar Messages

  • Remove Entry from Array

    Hi,just another question. Is it possible to remove an entry inside an Array without splitting up by using SubSet und with a combine after that? I found no function for that way...RegardsHenrik

    Henrik Skupin wrote:
    > Hi,
    >
    > just another question. Is it possible to remove an entry inside an
    > Array without splitting up by using SubSet und with a combine after
    > that? I found no function for that way...
    The new LabVIEW 6i has a "Delete from Array" VI that will do this more
    elegantly.
    Regards,
    John Lum

  • Remove element from array

    hi
    if i have an array
    eg
    int[] array = {4,2,1,2,1};
    how to i remove the index 2 from it and create a new array?
    thanks

    You can't remove the element--an array's size is fixed at creation.
    If you want a new array, create a new one that's one element smaller, then use System.arrayCopy to copy the elements you want to keep.

  • Remove multiples from array

    Hello, 
    I am trying to remove multiples of a fundamental frequency from an array of frequency points.  One extra issue with this removal, is that the multiple of the fundamental frequency from the array may be within a range, like +/- 1k.  Any help will be greatly appreciated.
    Thanks,
    hiNi.
    Solved!
    Go to Solution.
    Attachments:
    delete rows 2.vi ‏13 KB

    Give this a try.  You want to look at the remainder and then setup a couple of ranges based on the accuracy you want.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines
    Attachments:
    delete rows 2.zip ‏6 KB

  • Error #2025:The supplied DisplayObject must be a child of the caller - Removing Object from Array

    Hi guys, I'm pretty new to as3 and I'm trying to make a game where the player supposedly clicks on the stage and 3 towers which I've spawned dynamically should shoot towards the area. Everything works in terms of tower rotation, etc, but the bullets will not be removed from the stage when I exit the level into another scene. The boundary checking is fine, too.
    Here's a part of the code in the Main.as file.
    private function clickTower1(e:MouseEvent):void
    for each (var tower1:mcTower1 in tower1Array)
    var newLaser1:mcLaser1 = new mcLaser1();
    newLaser1.rotation = tower1.rotation;
    newLaser1.x = tower1.x + Math.cos(newLaser1.rotation * Math.PI / 180) * 40;
    newLaser1.y = tower1.y + Math.sin(newLaser1.rotation * Math.PI / 180) * 40;
    newLaser1.addEventListener(Event.ENTER_FRAME, laser1Handler);
    tower1BulletArray.push(newLaser1); stage.addChild(newLaser1);
      private function laser1Handler(e:Event):void
    //Make laser move in direction of turret.
    var newLaser1:MovieClip = e.currentTarget as MovieClip;
    newLaser1.x += Math.cos(newLaser1.rotation * Math.PI / 180) * laser1Speed;
    newLaser1.y += Math.sin(newLaser1.rotation * Math.PI / 180) * laser1Speed;
    //Boundary checking if (newLaser1.x < -50 || newLaser1.x > 800 || newLaser1.y > 600 || newLaser1.y < -50)
    newLaser1.removeEventListener(Event.ENTER_FRAME, laser1Handler); stage.removeChild(newLaser1);
    tower1BulletArray.splice(0, 1);
    I have a function called exitLevel, which basically, as the name states, exits the level when a button is clicked. It worked perfectly before I started coding the bullets.
        private function exitLevel(e:MouseEvent):void
    stage.frameRate = 6;
    gamePaused = false;
    clearLevel();
    gotoAndStop(1, 'exitLevel');
    btnExitLevel.addEventListener(MouseEvent.CLICK, levelSelect1);
      private function clearLevel():void
    stage.removeEventListener(Event.ENTER_FRAME, update);
    stage.removeChild(buttonCreep1); stage.removeChild(buttonCreep2);
    for (var i = creep1Array.length - 1; i >= 0; i--)
    removeChild(creep1Array[i]);
    creep1Array.splice(i, 1);
    //trace ("Creep1 Removed");
    for (var j = creep2Array.length - 1; j >= 0; j--)
    removeChild(creep2Array[j]);
    creep2Array.splice(j, 1);
    //trace ("Creep2 Removed");
    for (var k = tower1Array.length - 1; k >= 0; k--)
    removeChild(tower1Array[k]); tower1Array.splice(k, 1);
    for (var l = tower1BulletArray.length - 1; l >= 0; l--)
      stage.removeChild(tower1BulletArray[l]);
    tower1BulletArray.splice(0, 1);
    After debugging, it says the error is at the end, where i try to remove the child from the stage. What is wrong? Sorry, I'm a beginner at as3 so any answers might have to be spoonfeeding... I'll try to learn and understand, though. Thanks!
    I did take some of the code off of a guide on the web, and I don't understand it totally, so can someone explain to me what this code does as well? What is e.currentTarget? Thanks!
    var newLaser1:MovieClip = e.currentTarget as MovieClip;
    Here's the full .as file if anybody wants to take a look. http://pastebin.com/5ff4BQa5

    Hi, I managed to solve the errors (kind of) by using this code.
    for (var i:int = tower1BulletArray.length - 1; i >= 0; i--)
    if (tower1BulletArray.parent)
    tower1BulletArray[l].parent.removeChild(tower1BulletArray[l]);
    tower1BulletArray.splice(i, 1);
    However, the problem still persists that the bullets stay in the screen after I change the scene. Any solution? Thanks!

  • Removing Items From Array Collection

    Hi. I have an array collection which is made up of items
    defined in class PlayListEntry. I want to remove all the items that
    have the value of property select set to false. This is what i have
    come up with, it works fine, but only removes half the items at a
    time. I think this is because when you remove and item with
    removeitemat() it shifts the index of the items. How can i get
    around this?
    Code
    private function removeitems():void{
    for each (var ple:PlayListEntry in songCollection){
    if (ple["select"] != true){
    songCollection.removeItemAt(songCollection.getItemIndex(ple));
    }

    Here's a sample application I wrote that achieves what you're
    looking for.
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    layout="absolute">
    <mx:Script>
    <![CDATA[
    import mx.collections.ArrayCollection;
    [Bindable] private var medalsAC:ArrayCollection = new
    ArrayCollection([
    {Country:"USA", Gold:35, Silver:39, Bronze:29, select:true},
    {Country:"China", Gold:32, Silver:17, Bronze:14,
    select:true},
    {Country:"Russia", Gold:27, Silver:27, Bronze:38,
    select:true},
    {Country:"USA2", Gold:35, Silver:39, Bronze:29,
    select:false},
    {Country:"China2", Gold:32, Silver:17, Bronze:14,
    select:false},
    {Country:"Russia2", Gold:27, Silver:27, Bronze:38,
    select:false},
    {Country:"USA3", Gold:35, Silver:39, Bronze:29,
    select:true},
    {Country:"China3", Gold:32, Silver:17, Bronze:14,
    select:true},
    {Country:"Russia3", Gold:27, Silver:27, Bronze:38,
    select:true}
    private function filterItems():void {
    for(var i:Number = 0; i < medalsAC.length; i++){
    if(medalsAC
    .select == false){
    // => Remove item
    medalsAC.removeItemAt(i);
    // => Refresh collection so it see's new change.
    medalsAC.refresh();
    // => Start at beginning and keep looking
    i = 0;
    ]]>
    </mx:Script>
    <mx:Button x="10" y="10" label="Remove False Items"
    click="filterItems()"/>
    <mx:DataGrid left="10" right="10" top="35" bottom="10"
    dataProvider="{medalsAC}">
    <mx:columns>
    <mx:DataGridColumn headerText="Country"
    dataField="Country"/>
    <mx:DataGridColumn headerText="Gold"
    dataField="Gold"/>
    <mx:DataGridColumn headerText="Silver"
    dataField="Silver"/>
    <mx:DataGridColumn headerText="Bronze"
    dataField="Bronze"/>
    <mx:DataGridColumn headerText="Select"
    dataField="select"/>
    </mx:columns>
    </mx:DataGrid>
    </mx:Application>

  • Remove item from Array

    Hi,
    Can i remove a single item in my array or remove all elements???
    Tnx all
    Beck74

    This is a quick way to remove an element. It avoids looping which avoids an ArrayIndexOutOfBounds check with every iteration. Also, arraycopy is native which means that it is very efficient and suitable for large arrays.
    public class arraytest
        public static int[] remove(int _i, int[] _a)
         int[] b = new int[_a.length-1];
         System.arraycopy( _a, 0, b, 0, _i );
         System.arraycopy( _a, _i+1, b, _i, b.length-_i );
         return b;
        public static void main(String[] args)
         int[] a = {1, 2, 3, 4, 5};
         // remove element 3
         int[] b = remove(3, a);
         for( int i=0; i<b.length; i++ ) {
             System.out.println( b[i] );
    }

  • Remove text field from Array via for loop

    Hi,
    i have a problem to remove text fields added via for loop.
    That im doing is, via for loop im dynamically creating menu with 10 buttons.
    Each button contain, dynamically created, background (shape) and text field.
    And everything is fine.
    But when im try to remove text fields then i got this error:
    - Im using button to remove text fields - lang_btn.addEventListener(MouseEvent.CLICK, clickHandler);
    ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
              at flash.display::DisplayObjectContainer/removeChild()
              at Loading_Img_fla::MainTimeline/xmlLoaded()
              at flash.events::EventDispatcher/dispatchEventFunction()
              at flash.events::EventDispatcher/dispatchEvent()
              at flash.net::URLLoader/onComplete()
    In the script bellow marked with red is what should remove text fields from an Array, instead giving me error.
    Here is my script
    // Create for loop
    for (var i:int = 0; i < 10; i++)
              for each (xml in listItems)
                        if (i == xml.attribute("Id"))
                                  // Add MovieClip to stage to hold the data
                                  addChild(lmHolder);
                                  lmHolder.x = 0;
                                  lmHolder.y = 0;
                                  // Create new MovieClip to hold buttons
                                  lmButtonsMCArray[i] = new MovieClip();
                                  lmButtonsMCArray[i].buttonMode = true;
                                  lmButtonsMCArray[i].mouseChildren = false;
                                  lmButtonsMCArray[i].x = 20;
                                  lmButtonsMCArray[i].y = 20 + btCount * buttonSpace;
                                  // Add each button MovieClip to lmHolder MovieClip
                                  lmHolder.addChild(lmButtonsMCArray[i]);
                                  // Create Background to buttons
                                  lmButtonsArray[i] = new Shape();
                                  lmButtonsArray[i].graphics.beginFill(lmBgColor0, 1);
                                  lmButtonsArray[i].graphics.drawRect(0, 0, 230, 85);
                                  lmButtonsArray[i].x = 0;
                                  lmButtonsArray[i].y = 0;
                                  // <<-- Add Background shape to the buttons MovieClips
                                  lmButtonsMCArray[i].addChild(lmButtonsArray[i]);
                                  // Create a new array to preserve data from XML List
                                  lmNameArrayEG = new Array();
                                  lmNameArrayUS = new Array();
                                  // Create local variable to hold
                                  var lmTxtFieldContentUS:String;
                                  var lmTxtFieldContentEG:String;
                                  var lmTxtContent:String;
                                  // If clicked button is EG then make array with Arabic text
                                  // If clicked button is US then make array with English text
                                  if (footer.lang_btn.langState == "EG")
                                            for each (var leftMenuName:XML in egLanguageList)
                                                      lmNameArrayEG.push(leftMenuName);
                                            lmTxtFieldContentEG = lmNameArrayEG[i];
                                            lmTxtContent = lmTxtFieldContentEG;
                                  else
                                            for each (var leftMenuNameUS:XML in usLanguageList)
                                                      lmNameArrayUS.push(leftMenuNameUS);
                                            lmTxtFieldContentUS = lmNameArrayUS[i];
                                            lmTxtContent = lmTxtFieldContentUS;
                                  // Setup new text field each time script is executed
                                  lmTxtFieldsArray[i] = new TextField();
                                  lmTxtFieldsArray[i].width = 110;
                                  lmTxtFieldsArray[i].border = false;
                                  lmTxtFieldsArray[i].wordWrap = true;
                                  lmTxtFieldsArray[i].multiline = true;
                                  lmTxtFieldsArray[i].selectable = false;
                                  lmTxtFieldsArray[i].embedFonts = true;
                                  lmTxtFieldsArray[i].antiAliasType = AntiAliasType.ADVANCED;
                                  lmTxtFieldsArray[i].autoSize = TextFieldAutoSize.CENTER;
                                  lmTxtFieldsArray[i].text = lmTxtContent.toUpperCase();
                                  lmTxtFieldsArray[i].x = 10;
                                  lmTxtFieldsArray[i].name = "lmTxtFieldName" + i;
                                  // <<-- Add Text fields to the Movie Clip
                                  lmButtonsMCArray[i].addChild(lmTxtFieldsArray[i]);
                                  // If clicked button is EG then set Arabic text format, and make array with Arabic text fields
                                  // If clicked button is US then set English text format, and make array with Egnlish text fields
                                  if (footer.lang_btn.langState == "EG")
                                            lmTxtFieldsArray[i].setTextFormat(txtFormat_lm_eg);
                                            // Make array from text fields;
                                            pushEgTFintoArray.push(lmTxtFieldsArray[i]);
                                  else
                                            lmTxtFieldsArray[i].setTextFormat(txtFormat_lm_us);
                                            // Make array from text fields;
                                            pushUsTFintoArray.push(lmTxtFieldsArray[i]);
                                  // If clicked button is EG then loop thrue the for loop and remove English text fields from array
                                  // If clicked button is EG then loop thrue the for loop and remove Arabic text fields from array
                                  if (footer.lang_btn.langState == "EG")
                                            for (var rNr_us:Number = 0; rNr_us < pushUsTFintoArray.length; rNr_us++)
                                                      //remove the text field array from the display
                                       removeChild(pushUsTFintoArray[rNr_us]);
                                            //clear the array
                                            pushUsTFintoArray = [];
                                  else
                                            for (var rNr_eg:Number = 0; rNr_eg < pushEgTFintoArray.length; rNr_eg++)
                                                      //remove the text field array from the display
                                       removeChild(pushEgTFintoArray[rNr_eg]);
                                            //clear the array
                                            pushEgTFintoArray = [];
              btCount++;

    it looks like those tf's are children of  lmButtonsMCArray[i], not the current scope.  use:
    if (footer.lang_btn.langState == "EG")
                                            for (var rNr_us:Number = 0; rNr_us < pushUsTFintoArray.length; rNr_us++)
                                                      //remove the text field array from the display
                                        lmButtonsMCArray[rNr_us].removeChild(pushUsTFintoArray[rNr_us]);
                                            //clear the array
                                            pushUsTFintoArray = [];
                                  else
                                            for (var rNr_eg:Number = 0; rNr_eg < pushEgTFintoArray.length; rNr_eg++)
                                                      //remove the text field array from the display
                                        lmButtonsMCArray[rNr_eg].removeChild(pushEgTFintoArray[rNr_eg]);
                                            //clear the array
                                            pushEgTFintoArray = [];

  • Removes duplicates from a sorted array without having to create a new array

    Funcation removes duplicates from a sorted array without having to create a new array

    Funcation removes duplicates from a sorted array
    without having to create a new arrayIs a 'funcation' like a vacation but more fun or
    something?LMFAO. You just jumped with both feet on one of my biggest peeves. I've been outed!
    Actual words/phrases I've seen used which I hate with every fiber of my being:
    "Mrs. Freshly's"
    "McFlurry"
    "Freshissimo"
    "Spee-dee"
    "Moons Over My Hammy"
    One of my favorite SNL skits had Will Ferrell leading a panel of movie reviewers (they're the worst for this kind of junk). Each one had some cheesy pun to describe their respective movie. Ferrell topped the show off with his endorsement of "Fantasia 2000 is Fantasgreat!"
    LOL.
    "Come to Slippy Village - it's a FUNCATION!"
    &#167; (runs off, laughing maniacally, head explodes)

  • How to eliminate or remove zeros from 1D array

    How to eliminate or remove zeros from 1D array. Let say I have 1D array having foolowing elements
    "0 0 0 0 0 4 0 0 9 0 0 1 4 0 0 0 0 0 0 0 0 10 9 0 0"
    So after removing or eliminating zeros it will become as follow
    "4 9 1 4 10 9"
    So can any body guide me how can I do that? See attached Image for details.
    Thanks 
    JK

    altenbach a écrit :
    hchiam wrote:
    Here are 2 example .vi's I made based on altenbach's removeZeroes.png in this discussion thread: 
    It seems pretty pointless to post those because no new useful information is given.
    Currently, only the input is defined in the connector pane, making them useless as subVIs.
    unlike my example using integers, an "=0", like any "equal" comparison, is potentially dangerous with DBLs.
    Reshaping a 2D array to 1D before removing zeroes is pretty pointless because a 2D output cannot be recovered. A more interesting scenario would be to remove some columns or rows (e.g. that are all zeroes) from a 2D array.
    You should also clean up the front panel, e.g. properly zero the upper left corner, make the controls/indicators nicely labeled, sized and arranged, and maybe even add scrollbars to the arrays.
    Thank you for those comments.
    Now the input and output are defined (in the updated attachments) for use as example subVI's.  I also cleaned up a few visual details, but I leave the rest for others to cater to their specific uses if they don't want to use this as a subVI (or at least as-is), such as changing the icons or changing to integers instead of doubles.
    I'm not sure about what you mean exactly with "=0" being "potentially dangerous with DBLs".  I'm guessing you had a certain case scenario in mind.  Although the subVI's seem to work fine within my larger program and situation, my situation may not generalize with regards to this point.
    I reshaped from 2D to 1D, with a 1D output, because it could be helpful for things like when later processing just needs a 1D array.  For example, in my situation I had to remove a huge spike of unnecessary "0"'s from a previous subVI that were affecting the output display of a certain histogram.  So it turned out a 1D array output was helpful, and you never know what problems come up, so I included the 2nd example.
    Hopefully if someone is looking for this, they can just use or play with an example subVI (granted that they know how to plug things in for their context).  I was hoping to post a subVI people could put to direct use.

  • How to remove item from my array

    hi, I have one array with items. now I want to remove all items from array. How it can be possible ?

    You're welcome.
    I have noticed a few silly mestakes in my posts. You probably caught them, but just for clarity:
    1. yourArray.length without brackets ();
    2. < instead of <= in the loop conditions;
    3. when looping with pop() function, the initial length of the array has to be saved in a variable and this variable should be used in condition, because with each loop the length of array changes:
             var arrayLen:int = yourArray.length;
              for (var i:int = 0; i < arrayLen ; i++)
                   yourArray.pop();

  • How do u remove something from an array (char)

    (sorry im have just started to learn java.)
    if (Character.isWhitespace(inputTextArray[inputTextArray.length - 1]))
    inputTextArray[inputTextArray.length - 1] = null;
    how can i remove the value out of the position of the array im in.

    Once you've created an array, its size is fixed forever, so you cannot remove elements from it.
    What you will need to do is to construct a new array that contains the same text, but with the white space ommitted. Since you won't know how big the new array is until you've gone through the first one, you need something whose size is not fixed at the beginning.
    Given that you're dealing with text, I'd suggest you take a look at StringBuffer.
    Sylvia.

  • Memory/Speed of Split 1D array vs Delete from array

    Just wondering how Split 1D array works - does it create two new arrays in a new section of memory or does it just split the existing array in two, reusing the memory in place. (assuming that the original array is not needed elsewhere). If the latter is the case then presumably it is more efficient to use split array than delete from array if I want to remove element(s) from the beginning or end of the array. Is there a speed advantage as well?
    If I use split array but don't then use one of the output arrays is that memory deallocated or does the array remain in memory?
    Thanks
    Dave

    Ok please ignore the results I posted earlier, they are rubbish - not least because I got the column headings mixed up but also because my code was full of bugs
    So, here is a revised table, and the code - which hopefully only contains a few bugs... I'm not clued into benchmarking yet so please feel free to rip the code apart.
    I still get different results depending on where in the array I split it, most noticeably with subset and reshape. There is no effect with split. I'm guessing this is to do with the memory allocation. (I have not preallocated memory in my code, but I did wire the output arrays to Index Array)
    Message Edited by DavidU on 08-12-2008 04:49 PM
    Attachments:
    Benchmarks 2.png ‏13 KB
    split array test.vi ‏25 KB

  • Do you know a VI or a mean to remove plots from a graph?

    I'd like to remove plots from a graph and i know their
    x-cordinate do you know a VI or a mean to remove them?
    Thank you for yours answers.

    A graph is just a display of different points in graphical form. You can actually get the points out of the graph, remove the points of the plot you want to take out from the array, and put it back into the graph.
    Another way I've done it is to use the property nodes, and make the color of the line on the graph transparent. That way, the data is still there, but the plot is invisible.
    Mark

  • Removing zeros from data stream

    Hi
    I have incoming data (plz see attached diagram which shows the 2 states of the for loop '0' and default) which is a 1-D array of 64 bit real data .....it goes through the loop which removes zeros from the array.
    As I have 3 elements in the 1-D array (call them x,y,z ), the loop works very well for all values of 'y' and 'z' .
    However when x gets towards 1 and below say 10e-3 (it never is a negative number), the loop is rounding everything to 1 and then when the value gets between 1 and 0 (10e-3 for example) the loop leaves it out altogether and I just get y,z  values saved.
    Plz help me sort this out .
    Cheers
    Baz
    Attachments:
    zeros.PNG ‏25 KB
    zeros.PNG ‏25 KB

    If you want a tolerance comparison, try the attached VI.  I rewrote it from one in vi.lib after an earlier post.
    This account is no longer active. Contact ShadesOfGray for current posts and information.
    Attachments:
    CheckForEquality(DBL).vi ‏23 KB

Maybe you are looking for