LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to auto-index arbitrary dimension of a multidimensional array in a for loop ?

Highlighted

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 ?

0 Kudos
Message 1 of 8
(711 Views)
Highlighted

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.

 

 

Snap22.png

mcduff

0 Kudos
Message 2 of 8
(704 Views)
Highlighted

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?)


LabVIEW Champion. It all comes together in GCentral GCentral
What does "Engineering Redefined" mean??
0 Kudos
Message 3 of 8
(692 Views)
Highlighted

@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)

 

Pages.png


LabVIEW Champion. It all comes together in GCentral GCentral
What does "Engineering Redefined" mean??
0 Kudos
Message 4 of 8
(686 Views)
Highlighted

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 ?

0 Kudos
Message 5 of 8
(664 Views)
Highlighted

@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.

Message 6 of 8
(660 Views)
Highlighted

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.

 

 

snip.png

 

 

 

 

 

 

mcduff

Message 7 of 8
(656 Views)
Highlighted

@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:

 

ProcessPlane.png

 

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.

 

Array building examples.png

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

 


LabVIEW Champion. It all comes together in GCentral GCentral
What does "Engineering Redefined" mean??
0 Kudos
Message 8 of 8
(650 Views)