LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Array of indexexes

Highlighted
I have a LabView problem i thought was trivial before tying to
formulate the program loop.

I have an 1D array of turning points (integer) in which i want to
identify the "non turning points", that is two identical values
directly following each other. The output from the .vi that solves my
problem should be an array of the indexes of the "good" turning points,
where one of the duplicate points is omitted.

Any help would be greatly appreciated.




* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!
0 Kudos
Message 1 of 16
(2,351 Views)
here you go..

pelle wrote in message <2750ac20.50302477@usw-ex0106-041.remarq.com>...
>I have a LabView problem i thought was trivial before tying to
>formulate the program loop.
>
>I have an 1D array of turning points (integer) in which i want to
>identify the "non turning points", that is two identical values
>directly following each other. The output from the .vi that solves my
>problem should be an array of the indexes of the "good" turning points,
>where one of the duplicate points is omitted.
>
>Any help would be greatly appreciated.
>
>
>
>
>* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network
*
>The fastest and easiest way to search and participate in Usenet - Free!
>



[Attachment Turning Testd.png, see below]


[Attachment Turni
ng Testd1.png, see below]
0 Kudos
Message 2 of 16
(2,351 Views)
The reply from B&C Duffey did really solve my problem.
One of my colleagues solved the same problem with a more complex
solution. He was impressed by this short and consise solution

I'm wery greatful for the help

//Mattias Widmark //


* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!
0 Kudos
Message 3 of 16
(2,351 Views)
That code is certainly functional, but try this one. It's a little tighter and
if you're working with large large arrays it should run faster because LabVIEW
isn't needing to reallocate memory to hold intermediate results. The code as
shown returns the index of the element before the change in value. If you need
the index after the change simply add an increment before "Data out".

Mike...
[Image]

pelle wrote:

> The reply from B&C Duffey did really solve my problem.
> One of my colleagues solved the same problem with a more complex
> solution. He was impressed by this short and consise solution
>
> I'm wery greatful for the help
>
> //Mattias Widmark //
>
> * Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
> The fastest
and easiest way to search and participate in Usenet - Free!
0 Kudos
Message 4 of 16
(2,351 Views)
Hi,

how about wiring your 1D array of turning points to an index for-loop.
And within the for-loop just compare the last array-value with the
current array-value. If both values are equal omit it (via a case
structure), otherwise create your output array via the build-array
function.

Well this was the written explanation of the Labview program, which you
will get within the next few minutes.

Bye, Alexander


Sent via Deja.com http://www.deja.com/
Before you buy.
0 Kudos
Message 5 of 16
(2,351 Views)
I think that's what Duffy's solution is (not everyone can view PNG
graphics). It's the most commmon way to do it, even though it might be
slow on larger arrays (when it's better to alter the array instead of
creating a new one).

And, just to nitpick, you don't need anything hooked up to the "N", you
can just hook up a small wire from the array to the FOR loop and it will
auto-index.
_____________
|N|
|
Array =====|=====
|=|
|

Just turn off indexing for the first input, and on for the 2nd.

Rick
0 Kudos
Message 6 of 16
(2,351 Views)
Well, this thing is getting interesting!

If you compare Mike Porter's solution, you'll notice that it is at least 10x
faster than the other versions discussed here. Apparently, growing an array
(to an initially undetermined size) at the loop boundary is MUCH cheaper
than doing the same with the built array tool as in B&C Duffey's version. I
was not fully aware of that. I wonder if something could be more
optimized...

Of course I am always up to the challenge and I made a modification that
beats Mike's version by another 10% ( on a 1million point random array, on a
classic Pentium), YMMV. The VI is similar to Alexander's Idea, but instead
of growing the array, you initialize the blue array to the left of the shift
register with a worst-ca
se (=size of input) array, use "replace array
element" instead of "built array" inside the case, and, after the loop, you
just strip it back to the final size with "array subset".
This pre-allocates the array in one step and throws away the unused tail
later.

The speed difference is truly amazing! Could anyone comment on this?

Nobody has yet complained about attachments, so I added a picture of the
"business part". The other case just has the two blues wired through. (It's
not fully debugged and tested for "edge effects", may need another (+1) or
(-1) in some places).


So...who can built an even faster version ??? (no CIN allowed!)

Cheers
Christian




[Attachment new-2.gif, see below]

LabVIEW Champion. It all comes together in GCentral GCentral
0 Kudos
Message 7 of 16
(2,352 Views)
Huh. I never even thought about that. I'm not good with understanding
memory and LabVIEW's use of it (I'm still in school), but someone here I
work with knows a lot and he's explained that when you are usig 'build
array' it copies the entire array over to a new memory location every
time. So I can see why this is much faster. As an avid 'build array'
user, I think I'll do this from now on. It's pretty straightforward and
if it save's me time, it's well worth it.

One of these days someone is going to build a giant "Tips and Tricks"
webpage for LabVIEW. Any takers? Smiley Happy

Rick
rick@csciences.com

Chesapeake Sciences Corp.
1127B Benfield Blvd Millersville, MD 21108

Tel: (410) 923-1300 x3430 Fax: (410) 923-2669
0 Kudos
Message 10 of 16
(2,352 Views)
Yes it is clear that replace is always faster than built.

However, if you look at Mike Porter's solution, you see that he "builds" the
array from zero size at the autoindexing output terminal of the while loop.
Why is this nearly as fast as my solution? Why can't LabVIEW use that
mechanism for "built". It is possible that "built array" need to use a much
safer multipurpose algorithm because you can also use it to merge arrays,
add elements to the beginning or end, etc. The solution could be a special
"append element to array" that can take some internal shortcuts, but would
be much faster. As you said this might be an often used function.

Of course I'm just babbling now and don't really know the guts of LabVIEW...
.... and
I still don't know what an indexex (sic) is!

Thanks for trying.
Cheers
Christian

Rick Nelson wrote in message
news:38230AF8.5C980003@csciences.com...
>
> Huh. I never even thought about that. I'm not good with understanding
> memory and LabVIEW's use of it (I'm still in school), but someone here I
> work with knows a lot and he's explained that when you are usig 'build
> array' it copies the entire array over to a new memory location every
> time. So I can see why this is much faster. As an avid 'build array'
> user, I think I'll do this from now on. It's pretty straightforward and
> if it save's me time, it's well worth it.
>
> One of these days someone is going to build a giant "Tips and Tricks"
> webpage for LabVIEW. Any takers? Smiley Happy
>
> Rick
> rick@csciences.com
>
> Chesapeake Sciences Corp.
> 1127B Benfield Blvd Millersville, MD 21108
>
> Tel: (410) 923-1300 x3430 Fax: (410) 923-2669
0 Kudos
Message 12 of 16
(2,172 Views)
I must say that this newsgroup is certainly a very active one. After
reading about several new solutions to my problem i've completely
rebuilt my application using the suggested fast loop in two places. The
difference in performance is stunning.
Thanks a lot everyone for the ideas.


final note:
an indexex must be an array containing bad data... or a case of my
fingers getting stuck on the keyboard...

//Mattias //


* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!
0 Kudos
Message 13 of 16
(2,172 Views)