LabVIEW Idea Exchange

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

Last element index

It would be preety nice if all the VIs that can be indexed in any way (for example string and array operations) would accept "n" and "n-1" and such as input to denote that the user want the last element/character/etc. or the element before the last and so on.

example.png

15 Comments
GuenterMueller
Active Participant
Great idea. How will we create the constants "n" or "n-1"? Should there be an enhancement to the "Create Constant" menu that will allow us the select "Last Element". The selection of this menu item will generate the constant "n".
ryz
Member
Member

That is would be one way to go, but I imagined it to be as simple as just typing it into the constant field. (Simple for the user but a lot of job for the developers 🙂

Currently if a non-numeric character is written into the field it is ignored or it returns 0, which shows that it is already checked what character is given.

It would also be nice to implement this easy input for Inf

M_Peeker
Member

I don't agree that this is a good idea. Getting the last or n:th last element i easily and efficiantly performed buy using delete from array or reverse array followed by normal indexing. Adding the suggested constants will clutter the palette.

 

 

LastElementsSnippet.png



CLA
www.dvel.se
GuenterMueller
Active Participant
Reversing a string, then index from the beginning, then again reversing (if you intend to get the last n characters, i.e. n>1) is not that beautiful on the BD. I continue to like the initial proposal.
SteenSchmidt
Trusted Enthusiast

@M_Peeker: "Efficiently"? LabVIEW is a bit too easy huh... Sorry, but please don't make an extra copy of an array just to get an element from it. Get the length of the array and calculate the correct index. That's the only way, and simple enough in my book.

 

Cheers,

Steen

CLA, CTA, CLED & LabVIEW Champion
Intaris
Proven Zealot

I believe I read somewhere at an Array reverse does NOT make an array copy but sets an attribute bit that it has been inverted and is handled accordingly internally.  I'm not sure if I remember correctly but maybe someone from NI could chime in.....

 

I personally would like an option like setting the index of a file where we can select the "INDEX" input to the array element function and choose whether the index is measured from the start or end of the array.

GuenterMueller
Active Participant
@Intaris: I read that note, too. (Although I do not remember where to find it.) However: "Show Buffer Allocations" says, that memory will be allocated for the reverse operation.
M_Peeker
Member

@Intaris: Yup, thats what I thought too and it is mentioned among other places at the end of this article, but as @GuenterMueller sais, show buffer allocations claims that memory is allocated. Not sure what to believe, even if the buffer is allocated it is not granted that the buffer is used, this is decided at run-time by LV.



CLA
www.dvel.se
JB
Trusted Enthusiast
Trusted Enthusiast

Related idea I posted more than two years ago. In the comments, you will find a note from AristosQueue about reversing an array.

johnsold
Knight of NI

I think you get an extra buffer because the wire is branched before the Reverse node.

 

When I found myself using last element frequently I just wrote a little VI to do that.  Even made a small icon so it would not take too much BD space.

 

While this idea would be a slight convenience, I am not sure it would be worth the complications.