From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW Idea Exchange

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

Search 1D Array in reverse

Status: Declined

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

It would be a timesaver to have a Search 1D Array In Reverse! Obviously we can code this ourselves, but a LabVIEW function would make it handier (and hopefully faster).

11 Comments
RavensFan
Knight of NI

You should be able to do a reverse 1-D array then do a search on that.  If I remember correctly what I read in other posts, that reversing a 1-D array doesn't cost you anything in terms of time or memory, that LabVIEW just knows to index the array from the opposite end.

wireman
Member

Yes, that's what I usually do. But then you have to subtract the result from the size of the array and adjust the index accordingly, plus do the error checking to trap the condition that the element was not found, so if NI would do that for us, we'd have to think less (and it would take less space on the diagram), or if we made a VI to do it, it would be one less VI we'd have to keep track of.

Knight of NI

 


@wireman wrote:

plus do the error checking to trap the condition that the element was not found,


Why do you think this is an error condition? Besides, this does not appear to have anything to do with searching an array in reverse.

 

wireman
Member

I shouldn't have used the word "error". What I mean is that if there's no element found, you would still want to return -1 (like the normal Search 1D Array).

RavensFan
Knight of NI

But searching a reversed array with no element found would also return a -1.

wireman
Member

Yes, but if you put in arithmetic after the fact to correct for the reversal (i.e. array size minus the search output) then it's no longer -1. My point is that it's a minor nuisance to write the code, or maintain the VI that does the reverse search.

sletrab
Member

This is a Function which is very often used, and also you want often to seach reverse.

Yes there are workarounds. But think of the new features of the IndexArray of an For Loop. How much time can yu save. THis is the same.

wiebe@CARYA
Knight of NI

This should be possible. I found it before posting it myself. Consider this a "bump". It needs more kudos.

wiebe@CARYA
Knight of NI

And although the reverse array does not really reverse the data, it will create a copy of the data when the original and the reversed array are needed after the reverse. So it might cost memory and CPU. I think?

AristosQueue (NI)
NI Employee (retired)

> it will create a copy of the data when the original and the reversed array are needed after the reverse

 

No, it will not necessarily. If you're only reading the array, no. If you start modifying the array and using both, yes.

(If you modify the array and then call reverse again after the modification then also no.)