LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

find more than one element in a 1D array

Thomas,
 
Sorry, I did not mean to criticize or start a programming competition. Your code is equally sufficient for any normal array sizes, there is nothing wrong with it. (except, as I said: IF the arrays are "big" ... I shoud have said: IF the arrays are "huge") 🙂
 
 
About the difference between the use of "delete from array" vs. "reshape array" to simply truncate an existing array to a desired lenght:
 
"Delete from array" is a powerful tool with 3 inputs and two outputs. It can delete entire sections inside an array, then move the remaining higher elements down to fill the gap. It outputs the deleted portion too.
 
"Reshape array" is a much simpler tool. 2 inputs(in this case), one output. Two quotes from the online help on "reshape array"::
  • This function does not physically move the data in memory, but the memory is re-interpreted according to the reshaped array dimensions. This function pads or truncates the data if necessary.
  • You also can use it to increase and decrease the size of a 1D array.
If you simply want to truncate an array as in this case, it seems more complicated to me to wire three inputs instead of two. Then I also need to be careful that I select the right output. If I am not careful, I might get the deleted portion instead. Such mistakes happen! 😉
 
All this said, some casual testing did not show any significant differences in performance between the two truncation methods for this purpose, so I was probably wrong claiming code efficiency. 😞
 
For me, reshape is simply more intuitive to use.  (I'm not sure, but I think "delete from array" was not even available in LabVIEW 4.0) 🙂
 
Here's how I would truncate the array after using autoindexing on the loop boundary:
 
 
 

Message Edited by altenbach on 10-25-2005 01:00 AM

0 Kudos
Message 11 of 15
(1,966 Views)

Christian

No problem - I'm still happy to see "the wizard" in the forums Smiley Very Happy
And I did not want to associate the competition topic to you - as I said it's a general behaviour I sometimes see and don't like.

Anyway - thanks for the input about the two functions. I never noticed the one you mentioned - said this I now know a little bit more - thanks to "the wizard" Smiley Wink.

Thomas

Using LV8.0
--------------------------------------------------------------------
Don't be afraid to rate a good answer... 😉
--------------------------------------------------------------------
0 Kudos
Message 12 of 15
(1,955 Views)

Hi all of you,

Thank you for all your posts and messages...i'm sure i'll learn a lot with your annotations for solving this and other problems I'll find.

 

Thanks again

 

Larson

0 Kudos
Message 13 of 15
(1,951 Views)
One last (and probably low on the efficiency scale) solution would be to use matlab in this situation.  If the input array is X, and you are looking for all values equal to one, then the index of all elements equal to unity can be found by using:

index=find(X==1);
0 Kudos
Message 14 of 15
(1,944 Views)


@Robert.Bedford wrote:
One last (and probably low on the efficiency scale) solution would be to use matlab in this situation. 

But remember that matlab starts counting array indices at "1", not at "0", so the results will be slightly (but predictably) different. 😞

Of course if you use LabVIEW 8.0, you no longer need matlab to do any of this. Simply use the new Mathscript node! :D:D (see image).

 

Message Edited by altenbach on 10-25-2005 06:30 AM

Message 15 of 15
(1,935 Views)