LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Determining every even numbered index of an array

Hello, all!
 
I am working on a small VI to practice string manipulation. Do any of you know of a way to perform an operation on every even numbered index of an array?
0 Kudos
Message 1 of 7
(3,081 Views)
I have the quotient - remainder thingy to determine if *X* is evenly divisible by two, i.e. even-numbered, but cannot figure out how to do this to each index of an array. Something involving a for loop set to terminate after a number of iterations equal to the size of the array was along the lines of what I was thinking.
0 Kudos
Message 2 of 7
(3,075 Views)
I think you're on the right track.  Here's an example that I made up really quickly. I think this does what you want it to.
0 Kudos
Message 3 of 7
(3,050 Views)

You could just decimate the array into 2 parts , even and odds, no math required (even is defined as mod 2 remainder == 0 if you decide to go that way).

 

Paul

Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGA
0 Kudos
Message 4 of 7
(3,046 Views)
Close, but I'm trying to take each element from a string array, reverse the string at every even numbered index, and display a new string (NOT a new array) containing the original odd indexes, plus the reversed even indexes. i.e. "The quick brown fox jumps over the lazy dog" would become "The kciuq brown xof jumps revo the yzal dog". *My brain hurts, lol*
 
Here is what I have so far:
 
 
0 Kudos
Message 5 of 7
(3,038 Views)
All you need to do is to take your input string and convert it into an array using the Spreadsheet String to Array, assuming that each word is separated by a single space. Then, you can just autoindex this array and if the index you're working on is even, reverse it. Autoindex on the output and then use the Array to Spreadsheet String to get your updated string. This can be done this way:



You could use Paul's suggestion of decimating the array, but you have to take into account the number of elements. If the number of elements is not even, then you're going to be missing the last element (i.e., the last word). You can simply add this last word yourself.

Message Edited by smercurio_fc on 07-30-2007 01:11 PM

0 Kudos
Message 6 of 7
(2,985 Views)
Awesome, thanks everyone!

Message Edited by God's Templar on 07-30-2007 02:51 PM

0 Kudos
Message 7 of 7
(2,968 Views)