Jump to content

Array auto-indexing


Recommended Posts

It would be helpful to be able to choose which array index to automatically access in a For-loop. It's not too hard to handle for a 2-D array (by transposing beforehand), but it becomes more cumbersome for a 3-D array. I suggest a modification like the following, where all methods give the same result.

post-3889-1225746740.png?width=400

It may not be straight-forward to allow programmatic access of the array index - if so, it would be sufficient to have a popup menu to choose which index is used, and some visual indication of the usage, as in the lowest example.

The same method could also be used to determine how an array is built out of a For-loop.

Link to comment

This is a great idea - I have been having exactly this problem recently, working with 3D arrays.

An alternative would be a more powerful transposition function, something like the permute function in MATLAB, where you can freely re-order the dimensions of an N-D array. Then you could simply re-order the dimensions before/after the for-loop.

And while we're at it, how about something like the MATLAB squeeze command, which removes "singleton" dimensions, i.e. dimensions with size 1?

Alex

Link to comment

QUOTE (GregSands @ Nov 3 2008, 10:13 PM)

Yes! That's one thing that would really improve programming in LV.

It would also improve readability of the code a lot.

:thumbup:

QUOTE (GregSands @ Nov 3 2008, 10:13 PM)

It may not be straight-forward to allow programmatic access of the array index - if so, it would be sufficient to have a popup menu to choose which index is used, and some visual indication of the usage, as in the lowest example.

The edit-time-configuration would enable the compiler to optimize this code even further to get a bit more performance out of this.

In most algorithms a runtime-decision which dimension is to be indexed is not necessary.

Still there might be some occasions where a programmer would like to decide at runtime, which dimension to auto-index.

So this feature would be a "nice to have" from my perspective.

Link to comment

I agree with you guys that is would be a really nice feature to have for multiple dimension. Also, I like the idea of the permute function and it should exist in LV. In the mean time, I can share this VI I wrote some time ago to "Transpose" a 3D array. Its input is a 3D array of double and you specify which dimension remains unchanged.

Olivier

Link to comment

QUOTE (OlivierL @ Nov 5 2008, 05:39 PM)

I agree with you guys that is would be a really nice feature to have for multiple dimension. Also, I like the idea of the permute function and it should exist in LV. In the mean time, I can share this VI I wrote some time ago to "Transpose" a 3D array. Its input is a 3D array of double and you specify which dimension remains unchanged.

Olivier

Very neat Olivier - thanks! :thumbup:

Alex

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