LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

find more than one element in a 1D array

Hello!
 
I have a 1D array with 0's and1's...i want to obtain a vector with the position all of the 1's element.....i've tried to do with search 1D array...but when this block stops when find the first 1. There is a block for buildind this vector? How i can do to make something like this?
 
Thanks!
 
larson
0 Kudos
Message 1 of 15
(6,353 Views)

Hi larson

The function "Search 1D Array" has three inputs. The array, the value to search and the start-index. Start-index means, the search for given value starts at this position. So if you want to search multiple elements, just use this function in a loop and set start-index depending on the output of the function.

Hope this helps.

Thomas

Using LV8.0
--------------------------------------------------------------------
Don't be afraid to rate a good answer... 😉
--------------------------------------------------------------------
Message 2 of 15
(6,352 Views)

Hello becktho,

 

i've yet thought in this way but i don't know how i have to build this code using a loop, i don't knowhow hange the index array of the new array where i want to place the position of the elements.

 

Thanks!

0 Kudos
Message 3 of 15
(6,340 Views)
If I understand you correctly you would like to get the indexs of all the 1's (true) from the original array into a new array?  If so you can try out the below example (LabVIEW 7.1) or see the picture attached.  If not please clarify what you are wanting as an output...
 
 
Download All
Message 4 of 15
(6,317 Views)
Here is a simple example (LabVIEW 7.0).

Message Edited by altenbach on 10-24-2005 09:00 AM

0 Kudos
Message 5 of 15
(6,316 Views)

Additional comment:

If you are dealing with huge arrays, the "built array" node will slow you down due to memory re-allocation issues. For a much more efficient version, you can re-use the input array for the indices, then truncate it at the end using "reshape array".

Attached is a simple example, LabVIEW 7.0.

Message Edited by altenbach on 10-24-2005 09:18 AM

Download All
Message 6 of 15
(6,307 Views)

And here's another one..

 

Using LV8.0
--------------------------------------------------------------------
Don't be afraid to rate a good answer... 😉
--------------------------------------------------------------------
0 Kudos
Message 7 of 15
(6,283 Views)
Becktho, you're building an array with unknown final size which causes possible performance issues due to memory allocations IF the arrays are big.
 
True, I don't need the second shift register and can use the iteration terminal directly instead. (Also note that "reshape array" is a better and more efficient method to truncate an array instead of using "delete from array").
 

Message Edited by altenbach on 10-24-2005 10:47 PM

Download All
Message 8 of 15
(6,279 Views)
Hi Christian
 
The aim of my post was not to start the challenge who may code it better in terms of memory usage, execution time and speed, etc. I just simply wanted to show another way.
 
I'm aware of the fact of memory allocation and there are different ways to handle that. By the way - I think it is not the best way to replace the elements of the original array (although I can follow your code and although it is still possible to get the original values).
 
I think we should encourage others to think about different solutions - and not just this unique solution where memory usage is at 0.1%, processor load at 100% (we don't want to waste processor capacity)... I think you know what I mean. Often a more logically built vi is better for newbies than an extremly efficient one. I also think that you agree with me, if I say that there is not a best solution.
 
By the way - if you say that "reshape array" is better than "delete from array" - could you give numbers? Ok let's forget about the generation of the last element's index I've done in my vi - just the functions itself. For sure I'm not the ultimate programmer and there are lots of guys that are more experienced than me - but just saying "this function X is better than this function Y" without numbers or something similar - wow - that's quiet brave.
 
Don't think I can not be criticised and I don't want to criticise you. I've learned a lot from your posts (and I'm still learning), but I think the forums should not become the place to find out who is the best programmer (what sometimes seems to be the case). Don't link this to you - it's just something I sometimes feel when I have a look at a post.
 
Thomas
Using LV8.0
--------------------------------------------------------------------
Don't be afraid to rate a good answer... 😉
--------------------------------------------------------------------
0 Kudos
Message 9 of 15
(6,270 Views)
you can do this in another way also. Try this vi.
0 Kudos
Message 10 of 15
(6,262 Views)