Make index square array

I am writting a method that should create an array of 10 integers, where each element holds the square of its index number (thus, for example, myArray[3] should hold the value 9). Here is my code that does not work properly.
public int[] makeIndexSqArray(){
int[] myArray = new int[10];
for (int i = 0; i < myArray.length; i++)
myArray[i] = myArray[i] * myArray;
return myArray;
Any suggestions?
Thank you ,
Peter

Before this line:
myArray[i] = myArray[i] * myArray;
include this
myArray[i] = i;

Similar Messages

  • Labview 7 index waveform array by channel name string

    I was messing around with the index array waveform function with a waveform array(3 elements). I had used the set waveform attribute vi with the name input set to "Channel Name." The index waveform array function would not return any data when I was passing a particular channel name to it. Inside the vi I noticed that the name input has to have the format "NI_ChannelName" to match the string constant. Is this explained in the documentation anywhere?? Wouldn't it be more useful to make this string constant a string control input that we wired data into?? Then we could index the waveform array based on any name input that we set with the waveform attribute function.

    Hi 08,
    despite reanimating an 11 year old thread that information you requested is given in the "Set Waveform Attribute Function" help as written by Brandon…
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • Is it possible to make an ImageIcon array?

    Hi, I have been having some strange problems with ImageIcon...
    Here is my code...
    ImageIcon tiles[][] = new ImageIcon[5][5];
    tiles[0][0] = "1.png";
    I know this is not right, but basically, I want to make a 2dimensional array of imageIcon's, and then use a loop to set the link to the image. This is tough because I have not had any luck with this code. It works on strings, int's, float's, etc. but not on ImageIcon's grrrrrrr
    thanks

    All I want to do, Is make an array of ImageIcon's and then use a 2dimensional loop to draw all the tiles.
    problem one: I want to use a loop to create each individual ImageIcon, and since there is no "setfile" kind of function i tried making my own in the post above. But im simply trying to make a loop which sets all of the tiles to appropriate file names. (all the file names are numbers and then .png)
    Thats all I want to do, and I want to pass a parameter to a function which tells it the filename to set, and the specific ImageIcon in the array to modify. Hence why I had 2 paramater strings in the previous post

  • How to display on the graph three or more waveforms where time scale is not an index of array but a real time

    How to display on the graph three or more waveforms where time scale is not an index of array but a real time:
    I measure three voltages Va, Vb, and Vc on my Test stands every 3sec. So I’m building four arrays (Va, Vb, Vc, Time) and combine all in one.
    Time
    Va
    Vb
    Vc
    0
    5
    3.5
    2.8
    3
    4.9
    3.6
    2.9
    6
    4.8
    3.8
    2.1
    Now I need to show on the graph in which scale X is “Voltage” and scale Y is “Time”.
    How can I do it?
    Thanks a lot,
    Boris

    Hi, thanks all your reply.
    You may find "points_to_bar_graph.vi" from this website, I find it by this way.
    I will ask a stupid question: I don't have any photo processing software, how can I save the vi into a picture format?
    So here I just paste it into word document.
    Attachments:
    question.doc ‏520 KB
    points_to_bar_graph.vi ‏62 KB

  • Index an array of images only the last image shows

    Hi everyone,
    I try to index an array of images and all but the last element give me the error: "not an image."
    Here is a picture of the vi. The first for loop loads the images and stores them in an auto indexed tunnel. Every diagnostic I ran on this loop showed everything is fine. The second for loop should display the sequence of image stored in the auto indexed tunnel, but it does not. Instead I have the error message that elements 0 to n-1 are not images, and only the last image is displayed.
    What am I doing wrong?
    Thanks for your help.
    and the vi: 
    Solved!
    Go to Solution.
    Attachments:
    PulsedImageDisp1.vi ‏31 KB

    Speed of what? The second loop can't run until the first loop is done, and all the operations are linear. I'm guessing you're referring to the perceived speed of displaying the images one after the other so you don't have to wait for the next image to be read which is why you pre-load all the images. Otherwise, the overall speed should be the same whether you use one loop or two. Actually, to be technically accurate, the two loop version will likely be a little slower overall since LabVIEW has to allocate more memory to store all the images, while in the one loop version it is only ever dealing with one image. If the images are large then you might actually run into a memory issue with the two-loop version (arrays need contiguous memory). Just something to keep in mind and to be careful about.

  • Is it possible to make a 2D array (or whatever-dimension) array like..

    Is it possible to make a 2D array (or whatever-dimension) array like this...
            collumn 1                   collumn 2
    Emulated Address   Real Memory address*
               (int)                            (int *)
    +----------------------+----------------------------+
    |            0                |              0xA0               | <-- row 1
    |            1                |              0xA1               | <-- row 2
    |            2                |              0xA2               | <-- row 3
    +----------------------+----------------------------+
    * A = Address.
    is it possible to make an array like that?
    if it is, please tell me how to do it...
    thanks.
    ... I'm trying to make an emulator to emulate the simplest memory.

    Given your other posts, I'm assuming you mean in C, right?
    If so, the answer is yes, but specifically how will depend on a needed clarification of your question.  What you present doesn't really need to be a 2 dimensional array, just one: that looks like a simple list of memory addresses, right?
    At the simplest you can declare an array with two dimensions `iny myarray[2][3];` but to make the table you put up there you'd only need `int *myarray[3];`
    If you also wanted space allocated somewhere that each element of that list pointed to, you could allocate them separately:
    int *myarray[3];
    myarray[0] = (int *) malloc(sizeof(int));
    myarray[1] = (int *) malloc(sizeof(int));
    myarray[2] = (int *) malloc(sizeof(int));
    Obviously with many entries this should be in a loop.  Perhaps not as obviously, why would you not just malloc a larger block of memory to start with?
    What is the end goal?
    EDIT: actually, upon rereading your question, the mallocs are probably irrelevant.  `int *myarray[3]` will get you the array you are looking for.  Just realize that until you point those pointers to memory you 'own' you shouldn't assign to or read from them.
    Last edited by Trilby (2013-04-19 10:06:31)

  • Show biggest index in array with value "True"

    Hello,
    Is it possible to show the maximum index number with value "true", like shown underneath?
    I can show the value on what index the series of "true" ends with the "Array Max & Min" function, but when there is
    one False between those True's, it will show the index of the True left of the False.
    I don't need to know the size of the array, because it has to stay 8
    File is attached
    Solved!
    Go to Solution.
    Attachments:
    Biggest index of array with value 1.vi ‏8 KB

    Hi Stef,
    here you go:
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • Script or Action - Make image square

    Need to add this to an action, rather than making all images square manually before batching them all.
    - All 500+ images are various sizes both portait, landscape and possibly square already.
    - They are all cropped tightly around the product with a white background.
    So currently: I just use canvas size, anchor to the centre and change the smallest pixel dimension to make it square, so none of the product is cropped.
    Any ideas?
    I couldn't get JJMack's aspect ratio script to help me.
    Automate -> Fit Image will take it to 1000 pixels but still won't be square.
    EDIT: Oh my. I just found this, looks like it'll do the job. Will test some more in the morning.
    var savedRuler= app.preferences.rulerUnits;
    app.preferences.rulerUnits = Units.PIXELS;
    var w = app.activeDocument.width;
    var h = app.activeDocument.height;
    if(w>h) app.activeDocument.resizeCanvas (w, w, AnchorPosition.MIDDLECENTER);
    if(w<h) app.activeDocument.resizeCanvas (h, h, AnchorPosition.MIDDLECENTER);
    //if w==h already square
    app.preferences.rulerUnits = savedRuler;

    I have a need for this script as well...is this the entire script?  If not, can you post the complete script?
    I just need to increase either the canvas width (as white area for the added width/height) or the canvas height to match the longest side of an image so they they are perfectly square.  No cropping or reduction in image sizes.  These are product images on white background.
    Is this the full script?
    var startColor = app.backgroundColor; 
    if(startColor.rgb.hexValue != 'FFFFFF'){ 
    var white = new SolidColor(); 
    white.rgb.hexValue = 'FFFFFF'; 
    app.backgroundColor = white; 
    var savedRuler= app.preferences.rulerUnits;
    app.preferences.rulerUnits = Units.PIXELS;
    var w = app.activeDocument.width;
    var h = app.activeDocument.height;
    if(w>h) app.activeDocument.resizeCanvas (w, w, AnchorPosition.MIDDLECENTER);
    if(w<h) app.activeDocument.resizeCanvas (h, h, AnchorPosition.MIDDLECENTER);
    //if w==h already square
    app.preferences.rulerUnits = savedRuler;
    if(white != undefined) app.backgroundColor = startColor; 

  • Rewrite NVL/TRUNC to make index usage .

    Hi,
    I'm on 9.2.0.8 and got query like that
    select * from table
    where      
            TRUNC (SYSDATE) BETWEEN TRUNC (NVL (data_od, SYSDATE))
                           AND TRUNC (NVL (data_do, SYSDATE));Is there any better way I can rewrite this to make index on data_od data_do ubeing used ?
    Regards
    GregG

    smart000 wrote:
    select * from table
    where      
            TRUNC (SYSDATE) BETWEEN TRUNC (NVL (data_od, SYSDATE))
    AND TRUNC (NVL (data_do, SYSDATE));The requirement reflected by the sql seems odd (although it may be what u want) You want to check that that today's date should be between 2 date fields. But, If any of the 2 fields is null then you are replacing by today's date
    1. data_od cannot be a future date
    2. data_do cannot be a past date
    3. if data_od = null and data_do = null then you are thru', not check required
    4. if data_od = null then data_do has to be equal to trunc(sysdate) to satisfy the condition
    Please check whether the above in relation to your requirement, it may prompt something to rewrite the query.It's basically saying show me everything where data_od and data_do are set to today or either are null.
    4. if data_od = null then data_do has to be equal to trunc(sysdate) to satisfy the conditionThat's not correct. If data_od is null then trunc(sysdate) has to be <= trunc(sysdate) i.e. ignore the condition. Same is true (with >=) for data_do

  • There should be a way to index an array with an array of indexes or booleans (without a loop)

    Hi, often I would love to index an array with an array of indexes or an array of booleans without having to loop it.  I.e: let the IndexArray function accept an array of indexes instead of discrete indexes.  The output should then be an array of indexes values.  
    Another use case is to index with an array of booleans, so each TRUE element would index the input array and FALSE elements are not indexed.
    arrResult = arrInput[ arrIndexes ];  or
    arrResult = arrInput[ arrVal > 20 ];
    Would this be useful? Possibly it could be implemented in future versions?

    You forgot the link.

  • Square array

    I need to create a square array of integers with a specified size.
    Then I need to create a new square which should be read from a file.
    If I could figure out how to declare them'd probably be right with the
    rest but I don't know where to start. Any help would be appreciated.
    Thanks

    int[][] arr = new int[5][5];

  • How to make the new Array start at the same position as the previous and randomise only the newObjec

    So i am currently trying to make 5 boxes/ships (3Blue and 2 Green)appear  in a random position(1st-Gree,2nd- Blue,3rd-blue,4th-Green,5th-Green or in some other random way) i the upper corner of the stage.Make them move down.Then make a new 5 boxes and position them in the same starting position as the previous 5 and make only them get randomised (not with the previous 5,what it is doing at the moment).And do this while they are moving down.  so the code so far i have is this :
    import flash.events.Event;
    var shipCount:Number;
    var shipCount2:Number;
    var shipArray:Array = new Array();
    var shipArrayPosition:Array = new Array();
    var counter:int = 0
    var positionsX:Array = ["50","100","150","200","250",]
    addEventListener(Event.ENTER_FRAME, everyFrame)
    function everyFrame(ev:Event):void{
              counter++
              if(counter % 70 == 0){
                             doShips()
              positionShips()
              trace(shipArray.length )
    function doShips() {
              shipCount = 3;
              shipCount2 = 2;
              var gap = 10;
              for (var i:int = 0; i < shipCount; i++) {
                        var s = new Ship;
                        shipArray.push(s);
                        //s.x = s.width/2 + (s.width* i) + gap*i
                        //addChild(s)
                        //shipArrayPosition.push(s);
              for (var j:int = 0; j < shipCount2; j++) {
                        s = new Ship2;
                        shipArray.push(s);
              var array:Array=new Array();
              while (shipArray.length>0) {
                        var index:uint = Math.floor(Math.random() * shipArray.length);
                        array.push(shipArray[index]);
                        shipArray.splice(index,1);
              shipArray = array;
              //shipsArray has been randomized
              for (var k:int = shipArray.length - 1; k >= 0; k--) {
                        shipArray[k].x = positionsX[k]
                        addChild(shipArray[k])
    function positionShips() {
              for (var i:int = shipArray.length - 1; i >= 0; i--) {
                        shipArray[i].moveDown() //what the code in the Ship and Ship2 class does -> only: this.y += 3
    and how to make them stay at one position.Not to move in any X position when the new 5 are added

    This one is more efficient yet because it removes ships that moved out of view:
    import flash.display.MovieClip;
    import flash.display.Sprite;
    import flash.events.Event;
    var numShips:int = 5;
    var shipCount:int = 3;
    var shipArray:Vector.<Sprite> = new Vector.<Sprite>();
    var counter:int = 0
    var positionsX:Array = [];
    init();
    function init():void
              // populate positions
              for (var i:int = numShips - 1; i >= 0; i--)
                        positionsX.push(50 * i);
              addEventListener(Event.ENTER_FRAME, everyFrame);
    function everyFrame(e:Event):void
              counter++
              if (counter % 70 == 0)
                        doShips();
              positionShips();
              trace(shipArray.length);
    function doShips():void
              var gap = 10;
              var s:MovieClip;
              var shipsLine:Sprite = new Sprite();
              shipsLine.cacheAsBitmap = true;
              addChild(shipsLine);
              shipArray.push(shipsLine);
              shuffle(positionsX);
              for (var i:int = numShips - 1; i >= 0; i--)
                        s = i < shipCount ? new Ship() : new Ship2();
                        s.x = positionsX[i] + gap;
                        shipsLine.addChild(s);
              shipsLine.y = -shipsLine.height;
    function shuffle(a:Array):void
              for (var i:int = a.length - 1; i >= 0; i--)
                        var r:int = Math.floor(Math.random() * (i + 1));
                        var t:Object = a[r];
                        a[r] = a[i];
                        a[i] = t;
    function positionShips():void
              for each (var shipLine:Sprite in shipArray)
                        shipLine.y += 3;
                        // remove line that moved out of stage
                        if (shipLine.y > stage.stageHeight + shipLine.height)
                                  removeChild(shipLine);
                                  shipArray.splice(shipArray.indexOf(shipLine), 1);

  • Determine index of array within event structure

    I am doing some testing with dynamically registered events.  For these testing purposes, I have 2 separate arrays of boolean references hooked up to the dynamic input terminal.  The event structure is executing like I expect it to.  The only problem is that I want to know the index within the array for the event that triggered the value change event.  I would have thought I could use the CtlRef node to determine this, but instead it returns a reference to the actual boolean control that triggered the event.
    I could write a subroutine that searches for the label of the boolean that triggered the event within the arrays, but that is not efficient or good practice.
    So for instance, if I click on Boolean 2, I'd want the event structure to know it was array #1, index 1.  If I click on Boolean 6, I'd want the event structure to know it was array #2, index 2.
    Is this possible?

    That is a very good idea.  The caption is good to use for the label you show to the user.  You can change it to show different things, even programmatically, such as if you need to make your application more international and have it display controls in different languages to different users.  It lets you use longer or more descriptive names, without having those long names eat up block diagram space.
    Another thing I've done is take the control reference and search for it among the array of control ireference.  Search 1-D array will give you the index of the control within the array.  Then I can use that index and apply it to a different array and index out a value from that.  It could be a name, or perhaps a numeric value I use as a multiplier or something like that.  Just make sure there is a one to one correlation between the references in the array and whatever is the other array you are getting additional data from.  For what you have drawn now, it could be a little bit complicated because you actually have two different 1-D arrays of references.  But if you concatenated those arrays together, you'd have a single 1-D array you can search.

  • How to Use a Boolean Vector To Index an Array

    Say I have an array A = [1 2 3 4 5 6 7 8 9 10].
    I also have a boolean array B = [1 1 0 0 0 0 0 0 0 1].
    I want to use the boolean array B to pick out elements in A, creating a new array C = [1 2 10]. In MATLAB, I would just type C = A(B).
    I'm scratching my head trying to figure out how to do this. One solution would be to run through a for loop, querying B(i), and deleting A(i) if B(i) = 1. But this would change the size of A, so that the second time I did this, my index would be wrong.
    Anyone know a clean way of doing this?
    BONUS: If I have a 2D AA, with multiple columns, it would be nice to use B to pick out multiple columns of AA (in MATLAB, this would be CC = AA(:,B).
    Solved!
    Go to Solution.

    This can be done with auto-indexing with conditional tunnels.  The same approach could easily be applied to a 2D array, as well:

  • Iteration Speed issue when Indexing 3D array wried to a while-loop

    Brief Description of my Program:
    I am working on the real-time signal generation by using LabView and DAQmx (PCI-6110 card). My vi reads the big data file (typically 8MB txt file containing about 400,000 samples (complex double precision). Then, the signal is pre-processed and I end up with a huge 3D array to feed while-loop (typically 3D array dimension is N x 7 x M where N & M >> 7). Inside the loop, that 3D array is indexed and processed before the results are written to the DAQmx outputs. I have a speed issue when indexing the large 3D array (i.e, 3D array having a large sub-array size). My while-loop could not run fast enough to top-up the DAQmx AO buffer (at the output rate of 96kHz). It could run faster only if I use smaller 3D array (i.e, smaller-sized sub-arrays). I do not quite understand why the size of 3D sub-array affects the rate of looping although I am indexing same sub-array size at each iteration. I really appreciate your comments, advices and helps.
    I include my 3D array format as a picture below.
    Question on LabView:
    How does indexing an 3D array which wires to the while-loop affect the speed of the loop iteration? I found that large dimension of sub-arrays in the 3D array slows down the iteration speed by comparing to indexing the same size of sub-array from smaller-sized sub-arrays of the 3D array to perform signal processing inside the while-loop. Why? Is there any other way of designing LabView Program to improve speed of iteration?
    attachment:

    Thank you all for your prompt replies and your interests. I am sorry about my attachment. But, I have now attached a jpg format image file as you suggested.
    I had read the few papers on large data handling such as "LabVIEW Performance and Memory Management". Thus, I had already tried to avoid making unnecessary copies of data and growing arrays in my while-loop. I am not an expert on LabView, so I am not sure if the issues I have are just LabView fundamental limitations or there are any other ways to improve the iteration speed without reducing the input file size and DAQ output rate.
    As you request, I also attach my top-level vi showing essential sections such as while-loop and its indexing. The attached file is as an image jpg format because the actual vi including Sub-VIs are as big as 3MB in total. I hope my attachment would be useful for anyone who would like to reply my question. If anyone would like to see my whole vi & llb files, I would be interesting to send it to you by an e-mail privately and thus please provide your e-mail address.
    The dimension of my 3D array is N x 7 x M (Page x Row x Column), where N represents number of pages in 3D array, and M represents the size of 1D array.  The file I am currently using forms 3D array of N = 28, & M = 10,731.  Refering to the top-level vi picture I attached, my while-loop indexes each page per iteration and wrap-around.  The sub-VI called "channel" inside the while-loop will further index its input (2D array) into seven of 1D arrays for other signal processsing.  The output from that "channel" sub-VI is the superposition of those seven arrays.  I hope my explaination is clear. 
    Attachement: 3Darray.jpg and MyVi.jpg
    Kind Regards,
    Shein
    Attachments:
    3Darray.jpg ‏30 KB
    MyVI.jpg ‏87 KB

Maybe you are looking for

  • Windows Vista not recognizing ZEN Mi

    I upgraded to Windows Vista 32-bit ultimate, and my ZEN Micro is not recognized. I have let Vista search for drivers online automatically, but it finds no solution. Creative says there is nati've support, so why is my ZEN not recognized?

  • IF WE DOES NOT SELECT ANY VALUE IN SELECTION SCREEN WHAT WILL BE THE OUTPUT

    hi plz give me the answer for this

  • Open powerpoint encrypted files that are read only

    I'm trying to open a powerpoint encrypted file that is read only with keynote version 5.1.1. however keep getting the error message it must first be saved un encrypted. is there a way to mark the file read only so keynote will open it like powerpoint

  • Calling DLL FMI Objects in Labview

    Hello,          I am working with Functional Mock Up Interface between Modelica and Labview.          I have made an FMI Program and now comes the tricky part of Porting it to Labview(We use RT Target with a PCIe6343 Device).          The easiest and

  • [Solved] latest filesystem upgrade failed

    During last system upgrade ( pacman -Syu ),when upgrading filesystem-2011.08-1, the system hang for a while,  then pacman exit with some segfault error I tried to fix it by typing ` pacman -Syu ` again, then got another error when upgrading linux-3.0