LabVIEW Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
Mr._Jim

Delete From Array: Return Single Element When Deleting Length of 1

Status: Declined

Any idea that has received less than 3 kudos within 3 years after posting will be automatically declined.

Okay, I have a minor annoyance to whine about:

 

Have you ever noticed that, when deleting a length of 1 from a 1D array, an array rather than an element is returned from the "deleted portion" terminal?  To perform most actions on the deleted portion you have to use the "index array" function.

 

An example is illustrated below:

DeleteFromArray.png

 

I'm bracing myself to get called out on my laziness here, but if I'm to be honest I've always been a little annoyed to have to index out of that array.  Personally, I'd like to see this function return a single element when the length is set to "1".  Am I the only one?

 

6 Comments
JackDunaway
Trusted Enthusiast

I'll venture a guess as to why it behaves the way it does: length may change at run-time. Rather than overloading the prim based on a design-time constant being equal to '1', the LabVIEW syntax gurus settled on one implementation to handle all cases. (Same argument may be applied to 'Array Subset')

 

(As an aside, you may consider using a Queue with either a Dequeue or "Pop" action if you're always removing the first/last element)

SteveChandler
Trusted Enthusiast

I understand where you are coming from. If you wire a constant value of one to the number of items to delete then you know that you are only going to get one item back. So why would you have to go through the trouble of indexing it.

 

But if I have some code that dynamically sets the number of items to delete then maybe sometimes it is one and sometimes it is more than one. Let's say the deleted portion indexes a for loop. Now what?

 

An array is an array even if it consists of one element.

=====================
LabVIEW 2012


Mr._Jim
Active Participant

Jack, I was guessing the same thing.  Rather than overload it based on a specific, nitpicking contextual case, they left it syntactically versatile.  I understood that, I just figured that it wouldn't be an overly arduous task to add that extra case.

 

I think Steve summarized the underlying reasoning perfectly, though:

> But if I have some code that dynamically sets the number of items to delete then maybe sometimes it is one and sometimes it is more than one. Let's say the deleted portion indexes a for loop. Now what?

 

I guess I was subconsciously thinking about that case, but I apparently didn't think it through to a sufficient extent.  ...It's probably because I don't use the function in that context very often.  (The context whereby a dynamic number of elements are deleted)

 

Then again, here's how I would intuitively expect it to work:  Couldn't the function be written such that it discerns between a constant and a wire from some other type of node?  Admittedly, I've never written internal code to a LabVIEW function, but my hat's off to the geniuses at NI that have.

 

I'm enjoying this philisophical debate. :smileywink:

 

Jim

DJed
Member

The Delete From Array doesn't check whether it is wired to a constant of 1 because if you leave that terminal unwired, it defaults to 1. In the case where the length terminal is unwired, it defaults to 1 and a scalar is returned NOT an array. So simply delete the constant 1 and its wire and you will get the behavior you would like! 😃

SteveChandler
Trusted Enthusiast

I was just going to suggest that what you want would be the perfect little subvi.  Then DJed comes along and ruins the whole philisophical debate 🙂

=====================
LabVIEW 2012


Darren
Proven Zealot
Status changed to: Declined

Any idea that has received less than 3 kudos within 3 years after posting will be automatically declined.