Jump to content

Auto-indexing tunnel that appends rather than builds an array


Recommended Posts

The addition of auto-indexing to While and For loops was great. Sometimes, however, I have multiple nested loops and auto-indexing makes a 2D or 3D array, which is not necessarily what I want. It would be nice to have an auto-indexing tunnel that has a "auto-append" option rather than only the default "build array" behavior. Much like how the Build Array function has the "Concatinate Inputs" option. I guess this really makes the most sense for 1D arrays.

Link to comment

In the meantime, there's a fairly efficient workaround. You can use "Reshape Array" to morph the 2D back into 1D. If I'm not mistaken, this can be done without additional data copying. The values are already stored in contiguous memory in the desired concatenation-like order. As I understand it, a Reshape just transfers ownership of that memory chunk over to the (1D) output array wire.

I'm sure someone will correct me if I'm wrong...

-Kevin P.

Link to comment

QUOTE(Kevin P @ Sep 26 2007, 02:21 PM)

In the meantime, there's a fairly efficient workaround. You can use "Reshape Array" to morph the 2D back into 1D. If I'm not mistaken, this can be done without additional data copying. The values are already stored in contiguous memory in the desired concatenation-like order. As I understand it, a Reshape just transfers ownership of that memory chunk over to the (1D) output array wire.

Yes, that works, but only if the loop adds the same number of elements each time. It wouldn't work for this (pardon for not doing this in LV):

array a = {}; for (i = 1; i <= 3; i++) {	for (j = 1; j <= i; j++) {	   append j to a;	} }

This creates the array, a = {1, 1, 2, 1, 2, 3}.

Link to comment

QUOTE(eaolson @ Sep 26 2007, 09:40 PM)

Yes, that works, but only if the loop adds the same number of elements each time. It wouldn't work for this (pardon for not doing this in LV):

array a = {};  for (i = 1; i <= 3; i++) {	 for (j = 1; j <= i; j++) {		append j to a;	 }  }

This creates the array, a = {1, 1, 2, 1, 2, 3}.

Aaargh, there's some strange enscriptions there. I know they mean something...... Just... Can't... Figure... it.... out.....

Seriously, it's certainly a difference if the size of each iteration is different...... Good catch.

Shane.

Link to comment

Ok, I see your point. You'd want to do this with While loops as well. I didn't think of those -- I try to avoid auto-indexed outputs on While loops whenever practical. I'm not using 8.5 but I suppose the new For-Loop-With-Break would present a similar situation.

Your suggestion is the more universal approach. Good idea!

-Kevin P.

Link to comment

Good idea. You should probably submit it through the product suggestion center.

If I remember correctly, someone posted an Xnode which does this, but you can also create a simple LV2 global to do this - input the array and a boolean reset input and just build the array inside the subVI. Not as efficient memory-wise, but makes the diagram cleaner.

Link to comment

Join the conversation

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

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

×
×
  • Create New...

Important Information

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