Jump to content
Sign in to follow this  
gurj001

Data from while loop into array?

Recommended Posts

Im trying to send data to a array and want to use 'i' from the while loop as the index for the array.

Ive wired it up the only way i can think of but the array is still empty after running the VI

Any idea what im doing wrong??

See picture

(looking at 'average weight array')

post-583-1092595679.jpg?width=400

Share this post


Link to post
Share on other sites

It looks like you want to build an array in the loop and use the data logged in previous iterations. For persistent local storage, use a shift register. In the attached vi there are four arrays that are populated from a while loop that terminates after a set number of iterations.

The first array is trivial - it is populated and autoindexed from the while loop.

The second array is populated manually using a shift register and the "Insert into array" function.

The third array again uses a shift register, but only populates the itself if 'i' is an even number.

The final array uses two shift registers - one, is for local storage of the array (just like the above two arrays), but the second shift register stores previous values of 'i'. By right clicking on the shift register, you can add historical elements. So, the first shift register thingme on the right side of the loop is the last element stored, the next is the second last element, etc. As a result, you can keep track of variables from previous iterations. This last array only populates if the current value of 'i' is equal to the sum of the last two values (e.g. 1+2=3 - so 3 is a valid number). When the loop starts, it initializes all values. However, this is not necessary - you could make the vi reentrant and keep the value persistent for each call the this vi.

Hope this helps.

Cheers,

James

Download File:post-365-1092659541.vi

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.