Building 2D array in a while loop

I'm trying to build an array from hex data received from a serial device(using VISA) inside a while loop.  Can I take the hex string(262 bytes long) and write it into the first element of an array?  Everytime the loop is executed the next hex string  I would like to store  it into the next element of the array. Can someone give me some hints on how to get started or a basic vi that outlines building an array of this type in a while loop.  Thanks. 

Where is the 2D aspect of this? What you're describing sounds like a 1D array, and you can just use auto-indexing to do this.
To learn more about LabVIEW it is recommended that you go through the tutorial(s) and look over the material in the NI Developer Zone's Learning Center which provides links to other materials and other tutorials. You can also take the online courses for free.
Message Edited by smercurio_fc on 04-11-2008 04:07 PM
Attachments:
Example_VI_BD2.png ‏2 KB

Similar Messages

  • Add to new values to an existing 1D array in a while loop

    Hello,
    I have a while loop that collects data from a DAQ Assistant and stores it into a 1D array. The number of loops is set by the user. I am trying to average the data from each iteration of the loop. So far I am only able to get the array to overwrite the previous array values with the new ones.
    if Number of loops = 3
    First Iteration                      Second Iteration                         Third Iteration                           New 1D Array        [Divide by Loop #
    4.97                                      4.99                                               4.98                                            14.94                       for the average]
    4.97                                      4.99                                               4.98                                            14.94
    4.96                                      4.98                                               4.97                                            14.91
    4.98                                      5.00                                               4.99                                            14.97
    4.97                                      4.99                                               4.98                                            14.94
    I would like to make this as general as possible as the loop number will vary depending on the user input. 
    Solved!
    Go to Solution.

    sgtpppr685 wrote:
    I like the creative solution you have provided however, I am trying to keep the average at each element so that I can graph the average at each point. Therefore, I need the average to be a 1D array of the same initial length, not a scalar. 
    I am trying to avoid using shift registers.
    1. Do you mean you want the average after each iteration as well?  This can be done pretty easily by moving the division inside my loop.  Perhaps I am misunderstanding you though.
    2. Why avoid shift registers?  They are amazing and effective.  They are an essential LabVIEW tool imo   Plus they work wonderfully for your current problem.
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    If someone helped you out, please select their post as the solution and/or give them Kudos!

  • How to print an array out a while loop?

    Hi all,
    I'm very new with Labview (6h of Practice) and I meet a problem.
    I create a while loop in which a read the first characters of each line of three files and put it in an 2D array (3 rows and 50 lines).
    My goal is to print this array on the VI's panel in a Table or in a Multicolon Listbox. How to do this? In the While loop or out?
    I use Labview 6i.
    Thanks for your help

    Hi,
    I don't see any problems. I suppose that you can get a 2D array of strings from files.
    Now there are three solutions.
    1. Use of Arrays.
    Right-click on the wire with your 2D array and select "Create->Indicator" from pop-up menu. Now you have a 2D array on the front panel which will show you your data.
    2. Use of Tables.
    Select table control from "Controls->List&Tables". Paste it on the front panel of your vi. Right-click on it and select "Change to indicator" from pop-up menu. Then wire this indicato to your 2D array in the block diagram.
    3. Use of Multicolumn listboxes.
    Paste the multicolumn listbox to the front panel. On the block diagram right-click on it and select "Create->Property node" from pop-up menu. The property node of your control will appea
    r in the diagram. Right-click on it and change property to "Item Names" By selectring "Properties->Item Names" from pop-up menu. Now Right-click on the property node once again and select "Change to write" or "Change all to write" to toggle your property into write mode. Then wire your 2D array to this property node.
    The example is attached.
    Good luck.
    Oleg Chutko.
    Attachments:
    Tables.vi ‏26 KB

  • Methods to build an array inside a For Loop.

    Let me introduce to you my nested For Loops:  
    They output a 2D boolean array depending on two 1D boolean arrays of different lengths.  This is all well and good however, in another part of my program, I want this to be a 1D array instead.
    Idea #1:
    "I'll just reshape the array at the end. Simples!"
    Idea #2:
    "Hang on, why am I using three primitives outside the loop when I can use just one inside it along with a shift register?"
    Idea #2.5:
    "Oh, wait... I remember reading somewhere about continuously building an array (with concatenate inputs) inside a loop being a bad thing and quite slow. Let me test this."
    Spoiler (Highlight to read)
    Idea #3:
    "Umm... okay, so actually the second way is faster.  I think if I initialize the shift register first then replace subsets of the array, that might also be better."
    Spoiler (Highlight to read)
    Idea #4:
    "Yep - seems much better. (Something to do with LabVIEW not having to constantly allocate more memory on every iteration of the loop)  Looking at this closer, I don't actually need the inner For Loop because of the way I'm handling the arrays.  Try again...!"
    Spoiler (Highlight to read)
    Conclusion(?) #1:
    "Well I seem to have arrived at something that looks messier, but executes about 6x faster than my initial idea. That said, the difference rapidly increases as the input arrays get much bigger (becoming orders of magnitude different)."
    Is this the most efficient way of doing what I want?  Or is there something even better (and works in LV 8.5)?
    Never say "Oops." Always say "Ah, interesting!"

    Thank you both for the feedback.  It never occurred for me to recheck the logic after I'd initially extracted the nested For Loops, but the AND gate output is obviously the same now that it's been pointed out!
    Continuing on with Idea #4, I replaced the Select with an AND then compared the times.  (also meant I didn't have to initialize one of the arrays anymore)
    Spoiler (Highlight to read)
    It appears that the AND gate was slower but then I tried with different sizes of initial arrays and in one case, the timings were 'reversed'.
    This only happened when the top array (the one that is fed into the AND gate whole) was reduced to a length in the region of 5 elements long.
    Spoiler (Highlight to read)
    Why does this happen?  Is it something to do with the AND gate possibly being optimised for single element operations so smaller arrays are handled better...?
    Never say "Oops." Always say "Ah, interesting!"

  • Building an array from a for loop.

    Hi all
    I have a vi which reads from a file and manipulates the data using for loop. I am taking each element and multiplying it with a constant and converting it to I32. I would like to build back to a new array with the new values. I have attached the vi and a sample data file to read from.
    Please suggest if there are any better ways to do this.
    Thank you. 
    Solved!
    Go to Solution.
    Attachments:
    file_read.vi ‏11 KB
    file_read.txt ‏1 KB

    You can multiply the array with the constant and use the array instead of multiplying it with each element.
    The best solution is the one you find it by yourself

  • How to avoid Build Array function inside a For (while) Loop?

    Hi there,
    I have a simple question about how to avoid using Build Array function inside the loop. Now I want to remove the Build Array funtion inside the loop to improve the performance (To get better memory management). Any idea how to do that?
    Thanks a lot!
    Warmest regards,
    Chong

    It's been my experience that using the auto-indexing to build an array
    on a For loop is just as good as initializing and replacing elements.
    The For loop knows before it runs how many iterations it has to run and
    can allocate the array ahead of time.
    You're better off initializing and replacing when using a While loop
    because it does not know how many iterations it will run and can't
    pre-allocate the array ahead of time.
    Ed
    Ed Dickens - Certified LabVIEW Architect - DISTek Integration, Inc. - NI Certified Alliance Partner
    Using the Abort button to stop your VI is like using a tree to stop your car. It works, but there may be consequences.

  • How do we save three 1D arrays in while loop as an excel file? I used build array, waveform. I could not make it work.

    I have three separate 1 dimensional arrays in a while loop. I need to combine these arrays and save as a excel file outside the loop.
    My second question is that is there any emergency STOP button in Labview so that when I press that button, it cuts all the power going to the system. Thanks...

    Just a comment on the Stop button.
    It's not really a good idea to rely solely on a software emergency shutdown. Especially if the shutdown is to prevent some type of hazardous condition to the people running the test. The problem is that if your application or PC in general is having some type of problem, it may not be able to shut everything down as needed.
    You should always have a mechanical �Big Red Stop Button� that you can hit to cut power to everything. In addition to the button, I usually do have LabVIEW monitor things and if conditions are not looking good, have it automatically shut things down. This has always worked good, and I can�t remember any time I�ve actually had to use the big button, but it�s nice to know it�s there.
    VERY IMPORT
    ANT:
    Using the �Abort� button on the LabVIEW toolbar is NOT the thing to do. This stops your application where ever it is in its execution and does not allow it to finish or execute any shutdown code you might have put in. A �Kill� button on the front panel works well. I�ve put a single Boolean terminal in its own little While loop to monitor it. It usually writes to a digital line that�s holding a relay on that will cut the power.
    Ed
    Ed Dickens - Certified LabVIEW Architect - DISTek Integration, Inc. - NI Certified Alliance Partner
    Using the Abort button to stop your VI is like using a tree to stop your car. It works, but there may be consequences.

  • 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

  • Build 1D array using for loop

    Hi guys,
    I am testing out array. How do I create a 1D array of x-y using for loop?

    Nextal wrote:
    I am testing out array. How do I create a 1D array of x-y using for loop?
    OK, first of all you did not say what the array should contain. If you want an array that has one array element for each iteration of the while loop, you need to first think a bit harder. Your outer loop has no wait, thus it will spin millions of times per second and you will run out of memory soon, no matter how much memory you have. How many times should the while loop iterate? If you know the number before the program starts, you would use a FOR loop and autoindex at the loop boundary.
    If you want to use a whiile loop, you need a mechanism to keep the array size reasonable. For small final arrays, you can just build the array in a shift register if you need it updated as it happens. If you only need the array after the loop stops, you can autoindex at the right loop boundary.
    In any case, you should take a step back and decide what you really want. Currently the specifications are very vague and unreasonable.
    LabVIEW Champion . Do more with less code and in less time .

  • What is the maximum size of indexed array that can be created during execution of while loop?

    Hello,
    I am using a ring acquisition to take in images. If i write them as files in the loop, it slows down the acquisition unacceptably. Therefore i am converting image to array and storing the array until the acquisition is complete and then reading the array and converting back to image to save. The program sometimes runs out of memory (after a couple of minutes). Can anyone think of a way where i can store the array/images within the execution (without losing image information), without slowing it down and to avoid this memory problem?
    I have included the VI.
    Thanks in advance for any help or advice.
    kindest regards,
    FraserD
    Attachments:
    LL_Ring_in_IMAQ_8_bit_array_then_write_as_png.vi ‏94 KB

    When you build the array of pictures you do it using auto-indexing out of a while loop. That means that memory is aquired for a copy of the previous picture array and the array is rebuilt on every iteration, this is slow and requires a lot of extra memory.
    If you want to speed things up try initializing a shift register with a 3D array of a size that will be able to hold a certain number of pictures, then replace the "pages" as new pictures are aquired, replace operations do not require copying of the previous array and will thus be much much faster. The difference is exeptional when dealing with large arrays/amounts of data.
    Now, the shift register buffer could be built into a functional global, and you can add a push/pop logic to it so that you can have a p
    arrallell loop that works on writing the elements to disk. You could use a que for this, but I think even though you specify a size limit to the que it still aquires memory as new elements are added (correct me if I'm wrong people...:-)), so a functional global acting as a circular buffer og fixed size frame for a que should be better.
    MTO

  • How to build an array inside a loop

    Hi everyone,
    I have a basic question about labview. I would like to create an array in a "for" loop in that way:
    inside the loop, if a condition named "A" is verified, then, i add a new value to the first column of the array.  Otherwise, i create a new column, and start to add values to this column when the condition "A" is verified, etc.
    I put an example of a VI where the condition "A" is "the increment of the loop + 1 is not divisible by 5" and the values of the arrays are the increment of the loop + 1. The loop stops when the increment = 25.
    In this example, i have a single column with the values [1 2 3 4 6 7 8 9 11 12 13 14 16 17 18 19 21 22 23 24]
    while I would like to have an array of 5 columns:
    1   6   11   16   21
    2   7   12   17   22
    3   8   13   18   23
    4   9   14    19   24
    Note than this is just an example. More generally, the array can contain columns of different lengths.
    Thanx for your answer
    Andrew
    Solved!
    Go to Solution.
    Attachments:
    build_array.vi ‏9 KB

    You can't have columns in an array have different lengths - you can dynamically increase the size of the array (e.g. build array) but it means you will get the default value of the array in the other columns up to the new size of the array (normally 0).
    You will need to either keep track of the last index you wrote to for each column so you can trim it later or put an array in a cluster and then create an array of those (an array of a cluster of an array) - that will allow your column data array to have different lengths and you'll just need to unbundle/bundle the array before adding new items.
    Certified LabVIEW Architect, Certified TestStand Developer
    NI Days (and A&DF): 2010, 2011, 2013, 2014
    NI Week: 2012, 2014
    Knowledgeable in all things Giant Tetris and WebSockets

  • Using while loops instead of for loops in arrays?

    I am new to java and doing a java tutorial on using arrays and for loops. What im trying to find out is how it is possible to use a while loop instead.
    I would be very grateful if anyone can suggest a way of changing my code to use a while loop.
    The code I have written is:
    public class DetermineGrade
    public static void main(String[]args)
    final char[] mark = {'A','B' ,'C' ,'D' ,'F' };
    char [] grade = new char[5];
    int [] Score ={95,35,65,75};
    for (int i=0; i<4; i++)
    if (Score >= 90)
    grade= mark[0] ;
    else if (Score >=80)
    grade = mark[1] ;
    else if (Score >=70)
    grade = mark[2] ;
    else if (Score >=60)
    grade = mark[3];
    else grade = mark[4];
    for (int i=0; i<4; i++)
    System.out.println("grade = " + Score + ", " + grade);
    Thankyou LB

    Im trying to underdstand the differences in the
    different loops. I can grasp the for loop but I dont
    see how a while loop works, or how it id different
    from the other?
    for (j = INIT; j < MAX; j++) {
        // do stuff
    }is the same as
    j = INIT;
    while (j < MAX) {
        // do stuff
        j++;
    }Lee

  • How can I build a table with the time values of a timer from a while loop

    Hi:
    I have a question concerning building a table:
    Every 100ms I read a value from a sensor (while loop with a timer). I would like to build a table with the actual time and the concerning value. For example:
    0msec         1V
    100msec     2V
    200msec     3V
    300msec     4V
    etc.
    If I use the Express VI for building a table, I always get the date and time, but I don't need the date and the time is in the following format: HH:MMS, which is nonsensical for me as I can't differentiate within msec. Can I change the format anywhere?
    Can I also save the table to a file or even to an Excelsheet? How can I do that?
    Thanks for your help!

    Hi Craig:
    thank you very much. To solve the mystery : ) :
    I want to drive a stepper motor with a specific frequency. To get the current degree value of the motor I would like to measure the current time (from the beginning of the move on). (With a formula I get the degree value out of the time)
    Concurrently I would like to get data from a torque sensor and from a pressure sensor. That's why I asked you about the time and the table. The measurement should start with the movement of the motor. How can I do that? Right now I have different block diagrams (different while loops) (see attachment) and I would like to put them in one.
    I haven't done the block diagram for the pressure sensor yet, so there is only the one for the torque sensor and the one for the motor.
    I also would like to set a mark in the table when the voltage value of an analog input gets under a specific threshold value. Is that possible?
    I'm sorry, I'm a novice in LabVIEW. But maybe you can help me.
    Thank you very much!
    Steffi
    Attachments:
    motor.vi ‏238 KB
    sensor.vi ‏59 KB

  • While Loop to Monitor a 1D 8Bit boolean Array for changes

    Hi;
    I need help in monitoring a 1D 8-bit boolean array for a value change. I think I need to use a while loop with shift registers???
    Any suggestions?
    Thank you,
    4BoysDaD

    Where are you going to put it in your code. It will depend on what you are already doing. Here is an example to show you how to do it with out shift registers.
    Tim
    Johnson Controls
    Holland Michigan
    Attachments:
    Example.vi ‏8 KB
    Check of 1D Boolean Array has Changed.vi ‏8 KB

  • Making array while looping another array

    hi all,
    i have an array of int values.
    i need to make a list of another values while looping around the int values.
    but the values that are added to the list are objects
    can any one help me with the sample code in getting the list
    any ideas?
    regards and thanks in advance

    Double-posted
    http://forum.java.sun.com/thread.jspa?threadID=648140

Maybe you are looking for

  • How to measure true CPU usage?

    Hello, I have a program that runs on a Windows XP 32 bits machine with JRE 6u16 (8 [email protected], 16gig ram). This program gets 100,000 messages per minute, does something with it and republishes the data. We recently moved the same program to a

  • How do I sync protected AAC formated songs to my Ipod

    I have a 4th Gen iPod Nano and I have over 90+ songs listed in my Library that I notice have a "Protected AAC format" heading what ever that is), which WILL NOT sync and copy to my Ipod. I paid for ALL these songs previously and now, evidently, I can

  • Index not being used in access path

    Hi, I have been trying to rewrite a query which currently is taking almost 1min and 25 secs to execute. The database version is 11.1.0.7. The query is - SELECT COUNT(1) FROM TAB1 p WHERE p.ACODE = 24377 AND NOT EXISTS (SELECT 1 FROM TAB2 ph where ph.

  • Resource Breakdown structure role in Project Cost Allocation.

    Dear Experts, What is the role of resource breakdown structure while running project cost allocations? Is it possible that targets in the allocation process gets the cost allocated to the resources in RBS which is same for source as well as target pr

  • Enabling ports and services with svccfg

    Hi, I had a problem today which appears to have been a result of running jass security hardening on a system. The webconsole failed to restart, it was eventualy resolved by # svccfg -s svc:/system/webconsole setprop options/tcp_listen = true # svcadm