Iterating through every other (or specified number) of element in an array using a for loop

I am trying to go through an array but instead of autoindexing I want to skip every other element or maybe a number of elements that will be specified for the user.
Basic functionality that I want to acheive is the following in C code.
int temp_var = 10;
int i=0;
for(i=0; i<=1000; i=i+temp_var)
I am very new to LabVIEW and I did not know how to use internal variables.
Can this be acheived using shift registers?
I am attaching the code I currently have for this. Let me know what you think.
Thanks guys.
Solved!
Go to Solution.
Attachments:
24_Sep_NchanNSamp.vi ‏44 KB

tbob wrote:
I have been asking for a new For Loop style that would allow us to specify start, stop, and step conditions, but it seems that many people are just not for this idea.  Don't know why?
See here.
I wouldn't say there aren't many people for it.  The idea you linked to was one of a half dozen of basically duplicate ideas, including another one of your own.
These two ideas have a fairly large number of kudoes showing people want the idea.
Smart Iterators with Loops
For Loop Increment

Similar Messages

  • Problem cycling through elements of an array using a for loop ~ error 200609?

    Hi,
    I'm outputting a 194-element array from a MATLAB script node into a for loop where the array is indexed then converted into a 8-bit boolean pattern which I'm trying to output using DAQ Assistant. I'm using LabVIEW 8.2 and a PCI 6133 DAQ using a counter(Ctr0InternalOutput) to time the output. The first element of the array goes through the loop perfectly however never makes it's way back through and throws error 200609: Generation cannot be started because the slescted buffer size is too small. Increase the buffer size. After probing the line before DAQ Assistant I confirmed only one element makes it through the loop and then throws this error? I've trying doing the same things with lower lowel DAQmx vi's using a DAQmx configure output buffer vi to override this buffer size problem, but still get the same result(not the error but same data flow problem)? Anybody know what's going on? I've included the vi's I've been working with. Thanks!
    Millie
    Attachments:
    Untitled 22.vi ‏228 KB
    Untitled 34.vi ‏180 KB

    Hi,
    I'm outputting a 194-element array from a MATLAB script node into a for loop where the array is indexed then converted into a 8-bit boolean pattern which I'm trying to output using DAQ Assistant. I'm using LabVIEW 8.2 and a PCI 6133 DAQ using a counter(Ctr0InternalOutput) to time the output. The first element of the array goes through the loop perfectly however never makes it's way back through and throws error 200609: Generation cannot be started because the slescted buffer size is too small. Increase the buffer size. After probing the line before DAQ Assistant I confirmed only one element makes it through the loop and then throws this error? I've trying doing the same things with lower lowel DAQmx vi's using a DAQmx configure output buffer vi to override this buffer size problem, but still get the same result(not the error but same data flow problem)? Anybody know what's going on? I've included the vi's I've been working with. Thanks!
    Millie
    Attachments:
    Untitled 22.vi ‏228 KB
    Untitled 34.vi ‏180 KB

  • Using a For Loop Index for Array Element Number?

    Hi.  Thanks in advance for the help.  I can't seem to find what I want to do here using the search function... probably because I don't know how to frame the question appropriately.  Ignore the title to this post cause it's probably wrong vocabulary for what I want to do.
    Here's the situation:
    I have a 2D array where the first column is the X data and each subsequent column is Y data (call it Y1...Yn).  The n-value varies from run to run (some runs have 4 columns of data, some have 20), but that is easily gathered when reading the data file.  I need to perform a number of operations on each set of data, the least of which is smoothing the data and graphing it, so I'm limiting my discussion to these 2 operations.
    What I want is a for loop structure where the indexing of the loop tracks the Y1...Yn columns, grabs each column for the iteration, performs the relevant analysis, and spits out the result, but in a stackable manner.  Thus the title; I want to use the for loop's index to mark the array element for building a new array.
    See the image attached.  A 2D array of 9 columns (X, Y1...Y8) is analyzed such that each data set, (X, Y1), (X, Y2)...(X, Y8) is bundled, graphed, run through a B-spline Fit, of which is also graphed.  I need to replace this with something that looks like the for loop structure shown.  
    I just don't know how to get those two data bundles [(X, Yi) and it's smoothed pair] out of the for loop in a stacked set from every iteration of the for loop.
    Again the title, I think I want to build a new array where i use the index of the for loop to control the entries of the new array.  But I can't see how to do that.
    Any help would be appreciated.
    Attachments:
    NeedForLoopForThis.PNG ‏30 KB

    Hello H.R. Dunham, and welcome to the forum!
    It seems that you may be looking for Auto-Indexing, a basic feature of loops in LabVIEW.  You'll need to transpose your array before wiring it into the for loop, as elements are auto-indexed by row before column, but at that point you should be able to operate on each column and output an array of n cluster elements corresponding to your input columns.  Auto-indexing tunnels look like brackets to indicate each element will be indexed automatically- this should be the default when wiring an array into a for loop or when wiring anything out of a for loop.
    As for how to build your pairs, I suggest removing the X column and creating a "starter" cluster containing your X data and placeholder Y data before entering your "Y" processing loop.  Use the bundle by name function in the for loop to insert your processed column data into the cluster and auto-index the cluster output. Flow would be something like this:
    1) Gather data
    2) Split X and Y using standard array operations
    3) Create "template" cluster with shared X data
    4) Pass template cluster and Y-column array into an auto-indexed for loop.
    5) Insert processed Y data into cluster inside loop.
    6) Auto-index cluster data out of loop.
    This tutorial is probably also a good place to get started:
    Getting Started with NI LabVIEW Module 3: Loops
    http://www.ni.com/white-paper/7528/en/
    Hope that helps!
    Regards,
    Tom L.

  • Total number of elements in an array

    Hello, 
    I am trying to count the total number of elements in an array. 
    I have a simulate signal VI, that simulates a square pulse, this is being written into an excel file using the write to measurement VI, all for a given period of time. 
    I want to further chop a window of the signal depending on different paramenters (a trigger, which I intend to incorperate later, for now I am working of learning how to chop the data)
    In order to chop the data I need to know the array size, I use the array size funtion, I right click on the appeneded array in the front pannel and click show last element (array size -1) it doesnt match with the number of rows in the excel file written by the write to measurement VI, in fact it macthes with the "number of samples" I selected in the simulate signal VI. 
    Am I doing something wrong? 
    Why is there a miss match??
    I have attached my VI, Please help
    Thank You
    SP
    Attachments:
    FlashERGTrialVI 150218.vi ‏93 KB

    Hello RavensFan
    Thank you for the reply, I did incorperate the changes, but the same number is displayed in the indicator.  I've attahced my VI
    SP
    Attachments:
    FlashERGTrialVI 150218.vi ‏106 KB

  • Number of elements in an array

    Hi,
    I have been trying looking for a simple function to get number of elements is an array. Have gone though older posts but could not find answer to it.
    The function should work for following examples:
    char* name = "nInstruments"
    float state[] = {1.0, 2.0}
    I tried sizeof but it returns size of "type" in bytes. For example in example 2, it will just return 4.
    Does someone know a way to do it?
    Ciao
    RB
    Solved!
    Go to Solution.

    RB,
    In C, if an array is declared on the heap, as opposed to on the stack as in your example above, the sizeof operator only returns the length of the pointer that holds the array which, in a 32-bit program, is always 4 bytes. This is because the compiler has no way of knowing how many elements that array actually holds. The length of a C array is a fairly fluid concept. The real size of the array is usually determined by some memory manager somewhere (usually, malloc), but it's not something that the language itself has anything to say about.
    When you declare the entire array as a local variable, however, the compiler must create room for the full array on the stack, and therefore it is able to return the true size of the array via the sizeof operator. (The same is true if it's a global variable, even if it's not on the stack, in that case)
    For this reason, using the sizeof(array) / sizeof(array[0]) trick is iffy. It might work, or it might not work, depending on how the array is declared.
    For this reason, most C APIs that accept or return arrays, will usually also have some method of communicating the length of the array, usually as an additional parameter of some function. Because .NET APIs usually have no need to do this, the C wrapper for a .NET API in CVI does this for you when it handles .NET arrays. For example, here's what a function signature might look like:
    int CVIFUNC Namespace1_Class1_Test1DArrays (Namespace1_Class1 __instance, int * inA, int __inALength, char *** outA, int * __outALength, Namespace1_Class2 ** refA, int * __refALength, double ** __returnValue, int * ____returnValueLength, CDotNetHandle * __exception);
    Luis

  • How Do I Print the Number of Elements in An Array

    How do I print: "There are ____ number of elements in the array?"

    If you have a String holding a sentence, and if you split on non-empty sequences of whitespace (if the string has newlines in it, you'd probably need to pass the argument that makes \s match newlines, and for that you would probably need to use java.util.regex.Pattern -- see the docs and try some tests), when you'd get an array of Strings that were the non-whitespace parts of the original String. That makes for a reasonably good definition of the words in the sentence, although you could arguably get into some gray areas (does "isn't" count as one or two words? Does a sequence of numbers or punctuation qualify as a word?). In that case, counting the number of elements in the resulting array of String. using .length, would be a reasonable way to get the number of words in that sentence, yes.
    But rather than asking for confirmation on forums, why don't run some tests?
    import java.io.*;
    public class TestWordCount {
      public static void main(String[] argv) {
        try {
          BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
          String line;
          while((line = in.readLine()) != null) {
            int count = // your code here, to count the words
            System.out.println("I see " + count + " words.");
        } catch (IOException e) {
          e.printStackTrace();
    }Put your word-counting code in there, then run it from the command line. Type in a sentence. See how many words it thinks it found. Does it match with your expectation, or the examples given (hopefully) with your homework assignment?

  • Number of elements that can be used with 'in' Operator

    One of my SQL query having 'in' operator failed saying number of elements exceed.
    Is there a limit on number of elements that can be used with - 'in' operator.
    And if yes can it be increased?

    Parag Kalra wrote:
    One of my SQL query having 'in' operator failed saying number of elements exceed.
    Is there a limit on number of elements that can be used with - 'in' operator.
    And if yes can it be increased?You cannot have more than 1000 literals in an IN clause.
    Please check
    ORA-01795, limit on in clause
    Max number of values in IN clause
    Edited by: Rajesh Lathwal on May 24, 2010 12:28 PM

  • I've imported some midi tracks, used the mixer to set pan, volume etc, but when I stop playback and restart it sets every midi track back to '0'. I've been using LE for years, this is a new one, any ideas?

    I've imported some midi tracks, used the mixer to set pan, volume etc, but when I stop playback and restart it sets every midi track back to '0'. I've been using LE for years, this is a new one, any ideas?

    Hi,
    that's because Logic reads the volume information out of the imported MIDI tracks and sets the volume fader according to this information. The MIDI information overrides volume settings you have done, so you have to identify the MIDI events that contain volume (or expression or pan or whatever) information and delete them. You can use the event list editor for this.
    Fox

  • Current CC subscription turns into trial mode every other month... How to fix this once and for all?

    Current my current always promptly paid CC subscription regularly turns into Trial mode. This means I can use Apps in trial mode (how nice...), ask me to get a paid subscription, and at the same time happily charges my credit card. This happens every other months. Then I have to discuss this with their agents, which usually takes days to weeks, because they don't know what's going on. How on earth can this be fixed one and for all?!
    Thanks,
    Hinnerk

    Hinnerk do you have a case number from your previous contact with our support team that I can reference?
    If you have a valid membership then please see Sign in, activation, or connection errors | CC, CS6, CS5.5 - http://helpx.adobe.com/x-productkb/policy-pricing/activation-network-issues.html for information on how to resolve connection errors.

  • Actively changing number of elements in an array

    How do you use a control in the front panel to actively change the number of rows in an array which full of numeric controls?
    Is it possible to have this happen without the program to be running? Thanks for any help.
    Solved!
    Go to Solution.

    Chris B. wrote:
    Is it possible to have this happen without the program to be running? Thanks for any help.
    So you want this to work at edit time? Are you talking about the number of visible elements or are you talking about the actual size of the array (these numbers are unrelated!).
    In order for something to happen, "something" needs to be running. You could run another VI and use scripting to make changes to the array structure.
    You could also make an Xcontrol containing an array and a numeric. Xcontrols are fully operational even if the VI itself is in edit mode.
    If this is a program to run standalone, simply make sure the program is always running, but is in an idle state if nothing needs to be done at the moment. Now you can handle resize events if needed.
    LabVIEW Champion . Do more with less code and in less time .

  • Enable the Number of Elements in the Array

     
    once the Un-Initializing the array(1D or Multi) Placed ,we can not select the Number of element to Enable.
    byproviding the below option we can easily Enable the Elements in any array dimention.

    Already possible by typing a value (usually the default value) once you've set the indices to the size you want to initialize

  • Can we change the property of each element of an array using property node or by other methods?

    Hello all,
    Can we change the property of the elements of an array. For example:
    I have an array of combo-boxes. Can i have such a scenario that different combo-boxes of the array will have different items to select an item.
    I am able to set the different "values" in different combo-boxes bu using "to be more specific class" property node.
    But i could not set the different item list in different combo-boxes.
    Please give me the solution.

    Thanks a million dave!!!!!
    I have learnt a very new and innovative thing...
    I just wanna ask you one more question in the above context.
    Can i have listbox or combo-box in a table just like in an excel sheet where we can have listbox by using "data validation" property for different cells having different list.Can i have this in labview. Because for this i have to super-impose the combo-boxes on the table and treat them separately.
    We have to take those combo-box values and put in table and then store it.I have attached one VI to show the scenario.
    And this is the alternative solution of the array problem which u have already given. So please suggest me between the two or any alternative solution.
    Thanks,
    Ankit Madaan
    Attachments:
    Recording _Table.vi ‏19 KB

  • Counting number of elements in an array which aren't empty?

    i tried using this method to count an array which has 100 elements but it doesn't go past the while statement which i cant figure out?
    public static void countCust()
    int cntr = 0;
    int z;
    for (int c = 0; c < 100; c++)
    while (customer[c].indexOf(':') != -1)
    cntr++;
    javax.swing.JOptionPane.showMessageDialog(null, "There are " + cntr + " customers on record");
    }

    Are you getting NullPointerExceptions?
    Are you sure customer[] has been allocated?
    Are you sure each element in the array is non-null?
    BTW, it's traditional to use variables in loops that are closer to their mathematical usage. I mean, for an array index, usually you'd use variables named i or j, unless the indices map to coordinates in space, in which case you'd use x, y, and z.
    If neither of these is applicable, use a variable with a more meaningful name.

  • Photoshop Elements 10 on Windows PC. Re-installing Elements and it says my serial number is invalid. I have used this for the last 2 yrs. with no issues. What do I do?

    Why am I getting this message and what can I do to fix it?

    Serial number and activation chat support (non-CC)
    http://helpx.adobe.com/x-productkb/global/service1.html ( http://adobe.ly/1aYjbSC )

  • Retrive n number of elements from the collection using XQUERY

    <?xml version="1.0"?>
    <ns0:PNR >
        <ns0:num>num_1</ns0:num>
        <ns0:num>num_2</ns0:num>
        <ns0:num>num_3</ns0:num>
        <ns0:num>num_4</ns0:num>
        <ns0:num>num_5</ns0:num>
        <ns0:num>num_6</ns0:num>
        <ns0:num>num_7 </ns0:num>
    </ns0:PNR>
    In the above XMl i need an xquery to get below response:
    <ns1:PNRSet >
    <ns1:set>
    <ns0:num>num_1</ns0:num>
        <ns0:num>num_2</ns0:num>
    </ns1:set>
    <ns1:set>
    <ns0:num>num_3</ns0:num>
        <ns0:num>num_4</ns0:num>
    </ns1:set>
    <ns1:set>
    <ns0:num>num_5</ns0:num>
        <ns0:num>num_6</ns0:num>
    </ns1:set>
    <ns1:set>
    <ns0:num>num_7</ns0:num>
    </ns1:set>
    </ns1:PNRSet>

    Declare @x xml ='<?xml version="1.0"?>
    <ns0:PNR xmlns:ns0="whatever">
    <ns0:num>num_1</ns0:num>
    <ns0:num>num_2</ns0:num>
    <ns0:num>num_3</ns0:num>
    <ns0:num>num_4</ns0:num>
    <ns0:num>num_5</ns0:num>
    <ns0:num>num_6</ns0:num>
    <ns0:num>num_7 </ns0:num>
    </ns0:PNR>';
    with xmlnamespaces ('whatever' as ns0, 'the other' as ns1)
    , num as (
    select num from (values(0), (1),(2),(3), (4), (5), (6), (7),(8),(9),(10)) x(num)
    ), setFull as (
    select num / 2 as setNum, num + 1 as num
    from num n
    ), setNum as (
    select distinct setNum
    from setFull
    where @x.exist('/ns0:PNR/ns0:num[position() = sql:column("num")]') = 1
    select
    (Select
    x.val.query('.')
    from setFull s
    cross apply @x.nodes('/ns0:PNR/ns0:num[position() = sql:column("num")]') x(val)
    where n.setNum = s.setNum
    for xml path (''), type)
    from setNum n
    for xml path ('ns1:set'), root('ns1:PNRSet')
    Russel Loski, MCT, MCSE Data Platform/Business Intelligence. Twitter: @sqlmovers; blog: www.sqlmovers.com

Maybe you are looking for