Deleting from an Array?

I've written the following code to move everything in my array up one and replace the final value with a -1, yet it does not work and I can't figure out why...any ideas?
for(int j=1; j <= buffer.length-1; j++){
          buffer[j-1]=buffer[j];
          buffer[buffer.length-1]=-1;
          }It's kinda messing up the whole effect of my program.

Works .....
public class Primitives
public static void main(String[] a)
int[] buffer = new int[]{0,1,2,3};
for(int j=1; j <= buffer.length-1; j++)
buffer[j-1]=buffer[j];
buffer[buffer.length-1]=-1;
for (int i=0; i < buffer.length; i++)
System.out.println(buffer);
Lakshmanan

Similar Messages

  • Keyboard Delete button to delete row in array

    Is there a way to use the delete key on the keyboard to delete a row from an array?

    Hi Liz,
    If you are Using LV 6.1, this is easily done. There are three steps to the Process.
    1. Trap the Event when the Delete Key is Pressed. With LV 6.1 Event Structure can do this and give you which Key is Pressed Using VKey Node.
    2. There must be Some way that you can identify which row must be deleted. It could be a Simple Slider or Program output.
    3. The Physical deletion from the Array. With 6.1 you get a function "Delete from Array" and you specify either Column no or Row No to Delete.
    I have Attached a Sample VI for you to see in LV 6.1
    If you Do not Have LV 6.1 then Action 1 to Trap Delete Key Stroke is not In built LV function. You may Want to get "Danny Lauers ToolBOx" I think it is available at www.openG.org
    There is a Functi
    on in there"Get Keys" which will tell which Key is Pressed.
    Then you will have to Build Funtionality to Manipulate Array to Delete the row.
    Good Luck!!
    Mache
    Good Luck!
    Mache
    Attachments:
    Delete_Row_from_Arry.vi ‏30 KB

  • 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

  • How to delete rows from 2D array in this case...

    Hello. I'm just begging adventure with labview so please for patient. I created a program whitch suppose work in following way:
    2D Input array is array created by FOLDER BROWSING subVI. It works in this way,that browse folder and looking for txt files whose contanins measurment data. In my case subVI founds 4 files,and from theirs headers read information about what kind of data are in file also their's path. In this way is created 2D Input Array. subVI named PLOTS FROM PATHS ARRAY make picture with polar/XY plot. It's create only those plots and legends on one picture as many files(their paths) is setted to the program by output array. I made this subVI in that way and I would not like to change it. 
    My problem is that in even loop (witch check for any change by user) program suppose to relay anly those rows(files) for which checkbox are marked, e.g. marking anly 1 and 4 box, program should chose from input array row 1 and 4 only and pass them to output array,then  PLOTS FROM PATHS ARRAY subVI makes a picture only with 1 and 4 plot and legend only for plot 1 and 4. The best solution would be some relay witch is avtivated by logical signal. It lost to me ideas how to solve it, I'm just in blaind corner...
    I tried to use delete from array but I don't know how to do use it properly in this program,becease it can be only before or afeter for loop. Below is scan of front panel and also main problem. Please set me up somehow to solve this problem. 
    Regards 
    Solved!
    Go to Solution.
    Attachments:
    plots selector.vi ‏17 KB
    problem.PNG ‏18 KB

    I have attached a vi. Is this the one that you need?
    Anand kumar SP
    Senior Project Engineer
    Soliton Technologies Pvt Ltd
    Attachments:
    plot selector modified.vi ‏14 KB

  • How to delete a particular data from 3 arrays

    hello,
    i have a program that works like this.....
    import java.io.*;
    public class NewMain {
    BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
    String [] Type= new String[10000];
    int [] Num= new int[10000];
    float [] Price= new float[10000];///////
    and i am reading some of the data into these arrays
    so if i want to delete a particular data from the arrays how do i do that
    and if i want to delete pants from that file and enter the text again how do i do that.? any idea?....
    e.g if the file contains
    shirt
    32
    56.5
    pants
    56
    45.9

    Ashish.Uppin wrote:
    hello,
    i have a program that works like this.....
    import java.io.*;
    public class NewMain {
    BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
    String [] Type= new String[10000];
    int [] Num= new int[10000];
    float [] Price= new float[10000];///////
    and i am reading some of the data into these arrays
    so if i want to delete a particular data from the arrays how do i do that
    and if i want to delete pants from that file and enter the text again how do i do that.? any idea?....
    e.g if the file contains
    shirt
    32
    56.5
    pants
    56
    45.9
    Buddy, it seems to me that you are describing data that belongs together -- a class. You are probably better off with one arraylist of objects of this class, each object having a String type variable, an int num variable, and a float price variable, make that a double price variable.
    For examples of arraylists in action, please see the Sun java tutorials.

  • How to delete a random set of indizes from an array as fast as possible?

    Hello,
    My question sounds a bit like this thread but it isn't...    :-(
    http://forums.ni.com/ni/board/message?board.id=170​&message.id=129888&query.id=10689#M129888
    When sampling position/force/resistance data I use a time triggered sampling approach. For later analysis I need (among others) force (Y) over position (x).
    To get this I calculate the mean force from all time points with equal positions (as time is my common index). That works quite well but with arrays over 300000 points it becomes a bit too slow...
    These are my steps so far:
    1. Sort the position array
    2. Eliminate duplicates from the position array (no array reshape in loop)
    3. With the data from 2. get all indices where my original position array has a given value
    4. With the indices from 3. get the corresponding force values from the force raw data and calculate the mean
    In step 3 I need to search the whole raw position array as many times as there are different position values in itself.
    If I could delete all indizes I already found from the array to search that should (in theory) significantly improve performance. On the other hand such an operation would mean a lot of array reshape operations.
    What is the best approach to delete the found indizes?
    OR
    Is there no benefit in deleting the indizes as the array operations to do this need more time than they save?
    Thanks!
    Sören

    Now I'm getting a bit more confused about the app.  If you need a sampling rate higher than the encoder can provide, then then only way I can think of to accumulate multiple readings at the same position is if you have some type of bi-directional cyclical motion.  But if you originally used the encoder as a sampling clock, that seems to imply a unidirectional motion.  Is the motion cyclical or unidirectional?
    Knowing that I need to do some similar processing down the road, I did a bit of tinkering today.  The method I described earlier took ~350 msec to process (sort and then calculate averages force per unique position) on 350,000 data points.  A little more tinkering gave me a method that took <100 msec.  The machine was a pretty new test PC with a 2.8 GHz Pentium.  Here's an outline and perhaps I'll be able to scrub the code a bit to post soon.  Hopefully someone will have some even better ideas!
    The basic idea is essentially a histogram where each possible integer position value maps to a histogram bin.
    1. Based on knowledge of your test equipment, you can know the # of unique positions that can possibly be recorded.  Pre-initialize 2 arrays of this size before starting the main data acquisition.  Both should be full of floating-point 0's.  These will hold (a) count of entries and (b) sum of forces.  Call them the binning arrays.  My test used a size of 8000 possible positions.
    2. An auto-indexing For loop goes through the 350,000 integer positions and floating point forces.  The binning arrays enter this loop through shift registers.
    3. For each pair, use the integer position to map yourself to the appropriate index of the binning arrays.  Increment that element of the count array and add this iteration's force value to the sum array.
    4. After loop completes, divide sum array by count array.  These are your average forces.  (This is why the count is computed as a floating point value.  It was very costly to allow a type coercion from an integer count array into the division function.)  Note that unsampled positions should have 0 counts and produce a NaN result from the division.
    There are also ways to calculate a running average in the loop, but I haven't checked (yet) to see if it's faster.  The median you mentioned would need some extra post-loop steps.
    I'm sure that if this were a coding challenge, someone would cut the processing time at least in half...  Anyone out there?
    -Kevin P.

  • I want to insert 2d array (XY position)t​o XY graph and can delete the data from the array too.

    Firstly, I receive the data of X and Y position one by one seperately and then I add this two value (numeric double) to array two column (XY). After I press ok button the new data for X and Y will come and be added to the last row of my data. Then I use this data to plot in XY graph. All of this I did it already, but I want more additional function.
    My additional function is I want to add or delete a pair of data XY from the array at the row that I defined. This one I can not do it.....

    You use the Insert Into Array and Delete From Array functions on the Array palette. Here's a simple example in 6.0 that shows how they're used.
    Attachments:
    Insert_and_Remove_Row.vi ‏50 KB

  • Excel & ActiveX: Insert arbitrary columns from 2D array and create graph problems

    Hi there,
    I want to insert data from either a 1D or 2D array from LabView into Excel and create graphs.
    I used the information from the following example:
    http://www.ni.com/example/28934/en/
    and was able to create a new Excel file (I'm using Excel 2010), writing data from an 1D array to a column in excel by creating a while loop and using the first element of the array to write it to a specific cell. I use the counter of the loop to write to the next cell when the loop starts over and always delete the first value, which I write to the cell, from the array until it is empty.
    Now I also would like to write a 2D array - so the first column in Excel should be the first column from the array and so. Here I cannot use the loop counter directly as Excel only counts 1,2,... for the rows, but uses A,B,... to count columns. Also I do not know in advance how many columns my 2D array will contain, so creating a lookup table like (A means 1, B means 2,...) is not really an option (except there really is no other way). Is there a possibilty to convert numbers into letters or some way to 'explain' to the program that column 2 in the array means column B in Excel for example, or is there a way to insert new columns?
    I figured out how to add new Worksheets and as I also need to create a certain number of Worksheets and I know that on standard 3 sheets are present when creating the file, I use the 'add' methode to create every new worksheets before worksheet 3 - I could use the same methode to create new columns in Excel, but so far I didn't find a methode to do so. Or is there a way to enter the whole 2D array at once?
    Then I'd like to create a graph (in case of the 1D arrays a bar plot, when using 2D arrays a 3D plot) to view the data. I found this example:
    http://www.ni.com/newsletter/51339/en/
    -> as I do not have the toolkit I'd like to do it using ActiveX directly, so I tried to do things like shown under the headline 'DIY ActiveX/.NET'
    I tried to load the snippet to a new Excel file but got the error message 'microsoft.office.interop.excel.dll not found' and hence the code is not working. That confuses me a little as I would guess when this dll is not present I cannot access Excel from LabView at all, though my understanding of what I'm really doing so far is quiet limited. ;-)
    Also - as far as I understand from the snippet - when creating a new chart object I should be able the create methodes for it, however when I do a right click on the chart object of an ActiveX Worksheet symbol there are none listed.
    To explain my problems better I added a snippet showing my two problems: The inner of the two while loops shows how I import a 1D array. In the outer loop I seperate the columns. I know that currently this is not working as all data end up in column A of the Excel sheet - so I would need to convert the number of the outer counter to A, B,... or find a different solution.
    Moreover on the snippet I placed an ActiveX Worksheet Property with the Chart Object - as I can see the difference to the Chart Object in the example code from the last link above is the color. However I'm not sure what that means and how to change/ solve this.
    And just to make sure - I know this way the VI does not run as the Chart Object is placed completely wrong - I just did it, so it is included in the snippet.
    I'd be thankful for any suggestions,
    Thanks!
    Solved!
    Go to Solution.
    Attachments:
    ExcelAreaScan.png ‏60 KB

    Hello everyone and thanks for the answers.
    I only have the LabView Student Edition available here - is the toolkit included in it too. How can I check if it is installed/ available and in case it is installed - where can I find it?
    Today I had time to take a look at the example
    Create via ActiveX Labview a XY Scatter plot graph on an excel sheet
    It almost does what I want in terms of creating a graph. The only problem I could not fix, is that in this example a sheet is created where only the graph is present. i'd like to add the graph to a previously created worksheet. Today I tried get this working but it seems I stilll don't really understand what I'm doing, I'll post a snippet of my code as soon as I can access the PC with LabView on it again.
    I also took a look at the other example for inserting 2D attays - it seems to be what I need, I just had no time so far to test it, I'll post an update when I could test it.
    Thanks for the help so far!

  • How do I get a sub-array of even numbers from an array?

    I have a simple VI..
    First generate a 2D random numbers array. From this 2D array I have to show only the even numbers in a 1D array.
    I will thank you a lot!
    Solved!
    Go to Solution.

    take a look to what I've done.. I got a conflict with the case structure I used, this is, when the remainder is 0 then, store in an array, but if it's false(by default because in tru case is just wired) then store a zero.. My conflict was that I finally got an array of even numbers and zeros as the quantity of odd numbers.
    What I've done is resize the 2D array into a 1D and then sort it, then reverse the order so that the zeros of the array are all after the even numbers, then I used 'delete from array' from the index that zeros start, finally I got an array with only the even numbers, I have no problem with the result because the excercise asks me a range of random numbers from 13 to 69... but if it was from 0 to x all what I've done is no more efficient because I'd need the possible zeros that would appear by random generating.. I don't dominate arrays in labview, surely you have a completely more efficient solution to what I want
    Attachments:
    practica before exam.vi ‏15 KB

  • Filling a table from an array

    Dear all,
    I need your help in this issue please,
    I have this code that reads from a table A , fills an array and then insert into anoher table B the content of the array.
    The table A has a matrix table data:
    line column value
    1--- 1--- 133
    1--- 2--- 134
    1--- 3--- 1566
    2--- 1--- 5362
    2--- 2--- 822
    2--- 3--- 116
    Table B has the following structure and should be filled as follows by the procedure code:
    line ||| value_column_1 ||| value_column_2 ||| value_column_3
    1 ||||| 133 |||||||||||||||| 134|||||||||||||||||| 1566
    2 ||||| 5362 |||||||||||||| 822 ||||||||||||||||| 116
    The problem is that the procedure code doen't fill the Table B with the correct data, any suggestions about how to fix it please:
    +create or replace+
    +PROCEDURE proc(+
                                +P_param1 IN DATE,+
                                +P_param2 IN VARCHAR2,+
                                +P_param3 IN VARCHAR2)+
    +IS+
    +V_DESC                        varchar2;+
    +V_TabLine                number(5):=-1;+
    +V_PrvLine                number(5):=-1;+
    +V_TabVal                number(18,3);+
    +V_Tabcol                number(5);+
    +V_date                date;+
    +V_code               varchar2;+
    +V_grp                number;+
    +TYPE TabVal IS TABLE OF number(18,3)+
          +INDEX BY BINARY_INTEGER;+
    +W_ColVal        TabVal;+
        +CURSOR C_Crs IS+
        +SELECT  CDATE,CODE, GRP, CLINE, COL, RESULT+
        +FROM    TableA+
        +WHERE   cDATE        = P_param1+
        +AND     CODE        LIKE P_param2||'%'+
        +ORDER BY CLINE, COL;+
    +BEGIN+
            +DELETE FROM        TableB+
            +WHERE        CDATE =P_param1;+
            +COMMIT;+
            +For i_count in 1..10+
            +Loop+
                +W_ColVal(i_count) := 0;+
            +End Loop;+
            +open C_Crs;+
            +Loop+
                    +fetch C_Crs        into V_date, V_code, V_grp, V_TabLine, V_TabCol, V_TabVal;+
                     +exit when c_crs%notfound;+
                    +IF V_TabCol= 1+
                    +Then        V_DESC:= null;+
                                    +begin+
                                            +SELECT         DESC+
                                            +INTO        V_DESC+
                                            +FROM        DescTables+
                                            +WHERE        CODE =V_code+
                                            +AND                CLINE = V_TabLine+
                                             +AND                COL=1;+
                                    +exception+
                                            +when others then v_desc := null;+
                                    +end;+
                    +END IF;+
                    +IF V_TabLine <> V_PrvLine and V_PrvLine <> -1+
                    +Then+
                        +INSERT INTO TableB(+
                                +CDATE        ,Cind        ,CODE        ,Cline        ,+
                                     +FLD01        ,FLD02, FLD03)+
                             +values        (+
                                +P_param1        ,P_param2        ,V_grp        ,V_TabLine        ,+
                                     +W_ColVal(1)        ,W_ColVal(2), W_ColVal(3));+
                             +For i_count in 1..10+
                            +Loop+
                                +W_ColVal(i_count) := 0;+
                            +End Loop;+
                    +End If;+
                    +W_ColVal(V_TabCol) := W_ColVal(V_TabCol) + V_TabVal;+
                    +V_PrvLine := V_TabLine;+
            +End Loop;+
            +Close C_Crs;+
            +if V_TabLine <> -1+
            +Then  INSERT INTO TableB(+
                                +CDATE        ,Cind        ,CODE        ,Cline        ,+
                                     +FLD01        ,FLD02, FLD03)+
                             +values        (+
                                +P_param1        ,P_param2        ,V_grp        ,V_TabLine        ,+
                                     +W_ColVal(1)        ,W_ColVal(2), W_ColVal(3));+
             +End if;+
            +commit;+
            +return;+
    +End;+ Thank you in advance for your help.
    Edited by: user562674 on 15/02/2012 05:32 م
    Edited by: user562674 on 15/02/2012 05:34 م
    Edited by: user562674 on 15/02/2012 05:35 م

    user562674 wrote:
    but the problem is that in the future the number of columns may increase Then you have a BROKEN data model, not?
    too much so i need a dynamic way to fill the columns without enumarating them col 1, col 2, col3 because in the future they may be till col100Not possible - you will need to enumerate the columns to determine how to construct dynamic code to support variable columns. If this is a valid case for doing dynamic processing, then you need to write code that generates and uses dynamic SQL. And that adds complexity, potential run-time instability and security issues.
    There is no easy way to do stuff dynamically.

  • ISCSI Initator still connects to NAS after deleting OVM Storage Array

    I've got a 3.0.2 test rig with a couple of VM servers, a VM Manager and an Iomega NAS
    I have a working solution using NFS storage, so the next step was to get a working solution with iSCSI
    I started by enabling iSCSI and creating LUNs on an Iomega NAS
    I then created an iSCSI Storage Array in OVM which pointed at the NAS
    I registered a couple of iSCSI Initators in the OVM configuration.
    I then created a server pool etc and everything looks good
    Time to cleanup
    I deleted ISCSI based repository contents and then the serverpool.
    I deleted the LUNS from the OVM Storage Array definition
    I tried to remove the iSCSI Initators but it said it couldn't do that with an iSCSI generic initator
    I deleted the OVM Storage array
    I then went to the Iomega NAS to delete the LUNs and it says that there are still VM Server iSCSI Initators connected.
    I suspect I will be able to get rid of the iSCSI initiators connecting to the NAS by shutting down my two VM Servers and then rebooting the NAS. Since the VM servers aren't running there will be no connections coming from them so I will be able to delete the LUNS and turn off iSCSI.
    Should the delete of the OVM storage Array definition have deleted the iSCSI Initators or did I miss a step somewhere ?
    At this point, is there an easier to way to cleanup without rebooting everything ?

    After hooking up a couple of OVM3.0.2 servers setup to an HP P4000 VSA - I noticed that when deleting iSCSI LUNs first from VM Manager, and then from the VSA - after rebooting the hosts - the OVM servers would try to connect to the LUNs even though they had been deleted.
    If the LUN was deleted from VM Manager, but not the SAN - the LUN would just re-appear.
    If the LUN was deleted from VM Manager, along with the iSCSI Disk Array registration - the LUN would end up in 'unmanaged iSCSI array'.
    For some reason I can't seem to un-assign a server initiator from the arrays 'default access group'. I guess perhaps this is the problem.
    The only way to get around this is to delete the entire array registration!
    I created an SR and the latest news on that is that it's been filed as a bug.....
    Jeff

  • Error while deleting from BIA index

    HI EXPERTS GETTING BELOW ERROR PLZ GIVE CLARITY ON THIS:
         1.A communication error occured, with the TREX TcpIp     
         2.Error while deleting from BIA index; reconstruction required     
    THANKS &REGARDS,
    rAMESH,

    Dear Ramesh,
    Please check the connection with BIA. Please ask the Basis team to check the BW to BIA connection if they maintain it.
    YOu can go to rsddbiamon2 and check BIA connection availibility for more details.
    If that is right please try redoing the step at which you faced error and it should help.
    Please close the question if you have got the answer or solved it.
    Regards,
    Den

  • Voice memos do not delete from iPhone...

    How do I delete the voice memos that are stored on my iPhone 4, and are no longer on my MacBook Pro?
    My voice memos folder on my MacBook Pro was over 4 Gb, so I copied its contents to an external hard drive. I left the folder and deleted the voice memos from it. I then synchronized with my iPhone 4, with the hopes that those voice memos would delete from the phone. Unfortunately, they did not.  iTunes 11 only shows 4 voice memos, and the iPhone has all of them.
    If I control + click on any of the voice memos on my iPhone while looking at them in iTunes, those memos will still play. iTunes 11 does not show an option to delete these voice memos via option + click.
    I am running Mac OS 10.9.1, and IOS 7. Thank you for your advice.

    Nope, won't do it.  If I gently swipe right to left, it jumps to other songs randomly.  It has stopped playing the song as it did before I rebooted the phone.
    I'm familiar with the swipe process, as I can do it successfully with texts, reminders, and so forth.
    Now as I look through my artists, I see perhaps 10% of them are dupes, and none will delete.  And in all cases one of the songs will have an I-Cloud icon, while the other does not.
    Please explain to me why any of my 300 songs in I-Phone (out of 1900 in I-Tunes) should be coming down from the Cloud?  All of them were uploaded from I-Tunes; none were purchased from the I-Phone.
    Thanks, Jim!
    Peter

  • IMAP option to not delete from server OR recommend alternate mail app?

    Using POP in Windows computer and IMAP on iphone.
    In the iphone, POP has the opton to "delete from server: never"
    There seems no way to accomplish this in the stock mail app when using IMAP ?
    Using POP on the iphone is not an option due to the longstanding issue of the Apple mail apps not sending a  proper termination signal back. The mailbox remains locked until the server times it out for inactivity and cleans up the stale lock after 10 minutes. The result is "wrong password" on the computer if it then tries to retrieve during that period. It's a feature of POP by design to use a lock to prevent corruption caused by simultaneous access to the mailbox. BUT, BB,Android,Windows all handle this correctly so that their POP transaction (and the mailbox lock) only lasts seconds! Only ever see this persistent lock with Apple mail clients
    The user likes to keep his phone inbox clean, he will delete messages as he deals with them as well as messages he is postponing to deal with on computer later.
    Moving messages to a 'later' folder won't help, as that 'later' folder will not be available thru POP (for the computer)
    They also don't want to use IMAP on the computer because they don't want their communications stored on the server any longer than necessary.
    Can anyone recommend:
    - Windows IMAP client which downloads all and keeps a local copy of inbox which does not synch with server inbox.
    - Alternate mail app for iphone which allows "delete from device only // never delete from server "

    That's not how IMAP works. If you want to keep the inbox clean, but not delete the messages, create folders and move the messages into them for later review.

  • ITunes store says app is 'downloaded'. It's been accidentally deleted from my mac, so iTunes can't find it. How do I redownload it?

    Due to changing backup disks, some apps were deleted from my mac. iTunes says it can't find them, but when I look for them on the App Store, the button says 'downloaded', and there's nowhere to click to re-download them. Where do I go from here?

    Hey NeilJones,
    Thanks for the question. You’ll want to delete the app from your computer (even though technically it cannot be found). Once deleted from iTunes, you can return to your purchase history and re-download it:
    How to delete content you've downloaded from the iTunes Store, App Store, iBooks Store, or Mac App Store
    http://support.apple.com/kb/HT5772
    Mac or PC
    Open iTunes.
    From the Library pop-up menu, choose Apps.
    Click the app you want to delete.
    Press Delete on your keyboard.
    Download past purchases
    http://support.apple.com/kb/ht2519
    Thanks,
    Matt M.

Maybe you are looking for