Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Highlighted

03-12-2019 02:00 PM

Options

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

Labels:

Hi,

I want to use for loop to execute something on each page of a 3-dimensional array, but the auto-indexing only seem to work on the first dimension of arrays.

Also, there is no permutation function in labview, so I cannot rearrange dimensions beyond 2d arrays.

What I need is best described by the matlab code:

for i = 1:size(A,3)

A(:,:,i) = fun(A(:,:,i),i)

end

Any suggestions besides indexing it manually ?

Highlighted
Options

03-12-2019 02:07 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

You can try the in-place structure with the Split Array Option. Change the split dimension to access what part of the array you want.

mcduff

Highlighted
Options

** LabVIEW Champion. It all comes together in GCentral **

**What does "Engineering Redefined" mean??**

03-12-2019 02:26 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

You wire the index terminal [i] of the loop to the desired index input of index array and wire N according to the size in that dimension. Depending on where you wire, you get a 2D array in one of the three possibilities.

(The first dimension of a 3D array is typically a page. Do you have some simplified example code to show us?)

Highlighted
Options

** LabVIEW Champion. It all comes together in GCentral **

**What does "Engineering Redefined" mean??**

03-12-2019 02:34 PM - edited 03-12-2019 02:40 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

@altenbach wrote:

You wire the index terminal [i] of the loop to the desired index input of index array and wire N according to the size in that dimension. Depending on where you wire, you get a 2D array in one of the three possibilities.

Note that the top two versions are equivalent (and if you autoindex each at an output tunnel, you get a transposed (permutated?) version of the input array, depending on what index you are using).

Remember to disable autoindexing on the input tunnel.

(Note that some versions are more efficient than others because of memory order)

Highlighted
Options

03-12-2019 04:32 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

Thanks for answering.

Could you elaborate on the output part ?

**If I understand it correctly, auto-indexing (input) always index the first dimension, but the output auto-indexing adds the extra dimension at end.**

Then each dimension of the input array is -1 shifted (in the case of 2d array, transposed), which is kind of stupid.

How about the "build array" function ? Does it also add the extra dimension at the end ?

Highlighted
Options

**CLA // LabVIEW 2016 // BALUG // GCentral.org // Unofficial Forum Rules and Guidelines // Ask Smart Questions**

03-12-2019 04:42 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

@2A91312E wrote:

Thanks for answering.

Could you elaborate on the output part ?

If I understand it correctly, auto-indexing (input) always index the first dimension, but the output auto-indexing adds the extra dimension at end.

Then each dimension of the input array is -1 shifted (in the case of 2d array, transposed), which is kind of stupid.

How about the "build array" function ? Does it also add the extra dimension at the end ?

There is no transposing going on when a 2D array is auto-indexed into and out of a for loop. For a 2D array you are iterating through rows and then building up row by row at the output.

Build Array works similarly. If you input two 1D-Arrays those become the rows of a 2D array.

Highlighted
Options

03-12-2019 04:45 PM - edited 03-12-2019 04:46 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

Gregory beat me to the punch. He must be faster due to all the caffeine. (He likes to brew his avatar. I always thought he was a former java programmer.)

Below is a simple example to show you.

mcduff

Highlighted
Options

** LabVIEW Champion. It all comes together in GCentral **

**What does "Engineering Redefined" mean??**

03-12-2019 05:26 PM - edited 03-12-2019 05:42 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

@2A91312E wrote:

Thanks for answering.

You need to quote what you are replying to, else we cannot know.

@2A91312E wrote:

If I understand it correctly, auto-indexing (input) always index the first dimension, but the output auto-indexing adds the extra dimension at end.

It will give you a 3D array (rotated in 3D), where the first dimension picks the planes you operated on.

@2A91312E wrote:Then each dimension of the input array is -1 shifted (in the case of 2d array, transposed), which is kind of stupid.

No, this is smart and as designed. To operate on arbitrary plane in-place, you would just do as follows:

A shift register is one of the most efficient ways to operate on data in place.

@2A91312E wrote:How about the "build array" function ? Does it also add the extra dimension at the end ?

Build array has many options. If all inputs have the same number of dimensions, it can be built into an array with one more dimensions or you can switch to "concatenate" mode to append all inputs, keeping the dimension the same. Inputs to "built array" can differ by at most one dimension and if they different, the output will have the same number of dimension as the one with more dimensions and the rest will be added as elements, rows, planes, etc.). If the sizes are mismatched, the larger size wins and you get padding with default values for the datatype.

Here are some examples. Of course there are many more options and you can resize to as many inputs as you want. The only limitation is that inputs can only differ by at most 1 dimension.

For more complicated scenarios, you can use "insert into array" where any "direction" can be specified, e.g. to insert a column.