LabVIEW Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
JB

Index Last Element of Array

Status: New

A new function that indexes the last element of an array would spare some place on the diagram or avoid to use a subVI !

Or the Index Array function might be enhanced (First, specified Index and Last).

 

21748i0E884F1728A1398B

13 Comments
elset191
Active Participant

A somewhat related idea was submitted some time ago that might be of interest to you.  There's also a good discussion on why or why not it would be a good idea.

--
Tim Elsey
Certified LabVIEW Architect
AristosQueue (NI)
NI Employee (retired)

Just insert a Reverse 1D Array prim before the Index Array and leave the index unwired. The Reverse 1D Array does *not* make a copy of your array... it just annotates the output that this array should be walked backward.

jgcode
Active Participant

I use the Delete Primitive's deleted element.

By default it spits out the last element in an array

I am under the impression it doesn't make a copy - maybe someone could confirm.

Certified LabVIEW Architect * LabVIEW Champion
Darin.K
Trusted Enthusiast

Showing Buffer Allocations seems to imply that the Delete Element primitive does make a copy, even when the Array Output is not connected.  Not sure why it would have to though.

JB
Trusted Enthusiast
Trusted Enthusiast

 


Aristos Queue a écrit :
Just insert a Reverse 1D Array prim before the Index Array and leave the index unwired. The Reverse 1D Array does *not* make a copy of your array... it just annotates the output that this array should be walked backward.

 

Yes, this way is well known to me.

 

Because indexing the last element of an array is a very often used task, my main purpose is to spare as much as possible space on the diagram. Reverse 1D Array takes less place than Array Size + Decrement but still much more than an "all-in one" function would.

crash_override
Member

What I do is I increment a shift register variable or if there are multiple indices I need to keep track of I have a separate array of indices which I increment every time I add to the array. This approach works for me.

crossrulz
Knight of NI

As of LabVIEW 2014, the fastest way to get the last element of an array to use the Delete From Array.  In 2012, I apparently found a bug where the DFA did not "stomp" an unwired array output.  Some background can be found here: https://lavag.org/topic/16226-new-array-vi/ 

 

 


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
zou
Trusted Enthusiast
Trusted Enthusiast

The Reverse 1D Array doesn't work for 2D array.

Need get last row/column of 2D array.

 

George Zou
crossrulz
Knight of NI

Zou,

 

If you use Delete From Array, it will default to removing the last row (ie the "deleted portion" output will be the last row).  So if you want the last column, use a Transpose 2D Array before the Delete From Array.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
zou
Trusted Enthusiast
Trusted Enthusiast

But I don't want to make a copy of a big 2D array.

George Zou