LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Search element in unsorted 1D array of integers

Solved!
Go to solution

 

Hi 

I have unsorted 1D array of integers and want to delete few elements from it.

 

Scenario: 1D array [1 2 5 9 4 8 7]

                elements to be deleted [2 9]

 

I am aware Search unsorted 1D array.vi is available in array pallete and then delete can be used.

 

Suggestions on implementation is welcome

 

Thanks

 

0 Kudos
Message 1 of 10
(1,487 Views)
Solution
Accepted by topic author siddharth9678

Hi Siddharth, that function does work for integer arrays. I wrote a quick VI to do precisely what you need. This VI deletes all occurrences of the value that you want to delete.

Message 2 of 10
(1,469 Views)

Thanks Ravi for the solution.

0 Kudos
Message 3 of 10
(1,457 Views)
Solution
Accepted by topic author siddharth9678

@Ravi_Beniwal wrote:

I wrote a quick VI to do precisely what you need. This VI deletes all occurrences of the value that you want to delete.


Your code is extremely convoluted and inefficient. An operation that can be described in one sentence does not need a stack of loops, a case structure, shift registers, search operation and a barrage of "delete from array" operation in a tight loop (very hard on the memory manager because with each deletion, all higher elements need to be moved in memory because arrays are contiguous!)

 

All we need is ONE for loop and a conditional tunnel and code that fits on a postage stamp! (See attached. Your is 119kB, mine is 7kB, i.e. less than 6% of the file size!)

 

altenbach_0-1681917685268.png

 

altenbach_0-1681917854930.png

 

 

Message 4 of 10
(1,428 Views)

Thanks for the response...Solution is super optimized...will be doing this way...

0 Kudos
Message 5 of 10
(1,390 Views)

The original question was specifically about not being able to use the search element in unsorted 1D array function with integer arrays, and I was just trying to show that it works. There were no requirements around efficiency, code size in kb, or that it should fit on a postage stamp. This seemed like a question from someone new to LabVIEW who was struggling with some basics and not a coding challenge.

Anyway, thanks for your kind words!

0 Kudos
Message 6 of 10
(1,363 Views)

Hi Ravi...agreed with your statement...I am new to labview and changed the question after i realised i did some blunder in not being able to connect integer array input to search unsorted array.vi. Once i was able to connect, i edited the question. By that time u had already replied....Sorry for all the confusion.

0 Kudos
Message 7 of 10
(1,357 Views)

I did not see the original version of the question, but we are here to solve a problem, not elaborate why something does, or does not work, especially if that item is not even needed for the solution.

 

As a rule of thumb, "delete from array" should never (NEVER EVER!!!!) be used in a tight loop, it performs O(N²), thus scaling very poorly for large inputs (For example if all elements will need to be deleted, the last element would have been moved in memory about N times, even though we don't even care about it at the end!).

 

Using a tight FOR loop for rattling through an array is equivalent to "search array", because even "search array" needs to inspect each element in order one way or another, it is not a magical function that can skip that. 😄 (Yes, if the array is sorted there are shortcuts, of course)

 

A LabVIEW beginner should be shown a clean solution that is easy to understand, and only mine is. Showing code that is 20x more complicated only misdirects into the swamp and there will be significantly more places for bugs to hide or to make mistakes. 😄 We need to show how easy a solution can be to keep them interested. If we perpetuate a perception that LabVIEW is very complicated, some will just give up. 😮

0 Kudos
Message 8 of 10
(1,341 Views)

If the original question were about the best way to solve this problem, my answer would have been very different.

 

If I ask people for help with my motorcycle that wouldn't start, I don't expect people to come back with the advice that I shouldn't be using a motorcycle for transportation in the first place, because it may be more dangerous than other options, it won't protect me against the elements, or that there are cheaper or more eco-friendly options like a bicycle, etc. I would expect just some advice on how to troubleshoot the motorcycle that's not starting.

 

Anyway, I guess we have beaten this horse enough. Moving on.

0 Kudos
Message 9 of 10
(1,335 Views)

@Ravi_Beniwal wrote:

Anyway, I guess we have beaten this horse enough. Moving on.


Agreed. I prefer a horse over a motorcycle any day. 😄

 

The question was how to get from A to B. Well, if that motorcycle does not start and there is a beautiful Ferrari with a full tank and they key in the ignition parked right next to it (in the palette!), we don't really need to worry about the motorcycle. 😄

 

 

 

0 Kudos
Message 10 of 10
(1,327 Views)