LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Using a loop back node to build array okay instead of shift registers?

Attached is a sample of how I want to accomplish appending to multiple arrays and would like an opinion wether it is acceptable or not.  I didn't want to use 12 shift registers wired from the 6 possible case structures mainly because of esthetic reasons.  Each case will be called in turn during program execution only once.  So case 0 builds it's array then later case 1 and so on.  It seems to work but frankly manipulating arrays in LV confuses me a bit.  I cannot test in the actual program since the hardware the complete program controls is not yet installed.  Your input as to the wisdom of doing this or proposing a better solution (maybe one that actually works) Smiley Very Happy is appreciated
Mike
0 Kudos
Message 1 of 9
(4,209 Views)
You are inserting an element into an array once, there is no for loop or while loop.  Assuming that this nested case structure is going to be placed in a loop eventually, I would use a cluster that holds all 12 arrays and a single shift register.  If nothing else it will make the code much more readible.

Cheers
0 Kudos
Message 2 of 9
(4,198 Views)

A belated thanks for your suggestion jmchee.  I was on vacation last week
0 Kudos
Message 3 of 9
(4,156 Views)

I would need to see the context of your code.

However, building arrays one element at a time is very inefficient in Labview.

I would combine them into one 2D array that is pre allocated and then use replace array element function.

Every time you append another element into the array a copy of the data is made in memory.

This can get really expensive as the size of the array grows.

0 Kudos
Message 4 of 9
(4,124 Views)

You never have more than one element in each array since you initialize the shift register with every call of the VI.

Use "built array" instead of "insert into array", it's cleaner. However, since you only kep one elements, maybe you can jist place the scalar value inside a shift register. Make sure the default value is NaN so you know when it contains valid data.

All you probably need is an array of fixed size (12) and replace appropriate elements as need arises.

What you probably want is an action engine. See http://forums.ni.com/ni/board/message?board.id=170&view=by_date_ascending&message.id=240328#M240328

 

0 Kudos
Message 5 of 9
(4,121 Views)

A feedback node will not get initialized everytime the VI is called.

If you wire the init value that value will be passed on first call, after that its n-1

0 Kudos
Message 6 of 9
(4,116 Views)


fppf wrote:
A feedback node will not get initialized everytime the VI is called.
If you wire the init value that value will be passed on first call, after that its n-1

I strongly disagree! The initialized shift register or feedback node will get initialized everytime the subVI is called. Only uninitialized shift regsiters or feedback nodes will retain values between calls.
 
If you disagree with this, please provide an example that proofs your point. 🙂
0 Kudos
Message 7 of 9
(4,105 Views)

Shift registers and feedback nodes behave differently.

I would suggest you play with them a little to learn them.

A feedback node does not use the init like a shift register.

I don't need to write anything, here is the OP's code thrown in a for loop and run 100 times.

I had to wire the OP's connector pane

 

Download All
0 Kudos
Message 8 of 9
(4,084 Views)
Yes, you are right. The "global initialize" option is new and became available in LabVIEW 8.5.
 
Before 8.5, both shift registers and feedback nodes required to be in a loop and functioned the same. The new "global initialize" option allows the feedback node to stand alone.
0 Kudos
Message 9 of 9
(4,056 Views)