LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to sort an array in Even and odd parts


@apok wrote:

does it have something to do with memory use for efficiency in that 'in place' was developed?

 

sorry for the hijack...


I wasn't talking specifically about the "in place element structure", but used the term "in place" generically. If you have an array in a shift register, all operations that don't change the size (e.g. replace array subset") can be done in place, without need of new memory allocations. Whenever you resize an array (e.g. with "built array") an new memory allocation might be needed. This can be very expensive with large data structures.

0 Kudos
Message 21 of 40
(1,457 Views)

This is what I had in mind with the conditional indexing.

 

Ben64

 

EvenOddArrays.png

Message 22 of 40
(1,444 Views)

@ben64 wrote:

This is what I had in mind with the conditional indexing.


A bitwise AND with 1 is typically cleaner to determine even/odd. No need for divisions. 😉

Message 23 of 40
(1,428 Views)

That's something I hope to remember!

0 Kudos
Message 24 of 40
(1,420 Views)

Sir,

 

This is what I've tried after reading your instructions. Is it correct..?? Smiley Tongue

 

Array Sorting_new.JPG

0 Kudos
Message 25 of 40
(1,398 Views)

Now we are extremly happy you started trying right way.

Don't use insert array in loop , use replace array subset ( how? you find out )

for even odd use bit wise AND ( i have learnt this from altenbach )

give try again . you are on your way ...........

0 Kudos
Message 26 of 40
(1,391 Views)

Now I've tried this logic. This logic is sorting the array but not creating two different arrays...

 

new array.JPG

0 Kudos
Message 27 of 40
(1,380 Views)

To get two different array. you need to fill data in two different arrays.

Now you are using the single array and filling the data in that array in both the cases 

also put your array indicators outside the for loop.

 

0 Kudos
Message 28 of 40
(1,377 Views)

and just saw why you are not getting any value at all.

Initialize the array with some value and fix length before using replace array subset

0 Kudos
Message 29 of 40
(1,376 Views)

@T_reX wrote:

Sir,

 

This is what I've tried after reading your instructions. Is it correct..?? Smiley Tongue

 

Array Sorting_new.JPG


Please attach the actual VI (or a snippet) instead of pictures, because we cannot tell what is in the other cases of the case structure and there is thus insufficient information to debug. If you attach pictures, crop them! (The next picture you attached contains huge amounts of whitespace).

 

Some comments (you are learning fast!):

 

  1. The shift register needs to be initialized with an empty array, else the array will retain data from all previous runs and the array will grow forever. Simply right-click the left shift register and select "create constant".
  2. You probably want a shift register for the even array and one for the odd array. Wire it across the case where it is not modified.
  3. Use "build array" instead of "insert into array". No index needed. The order of inputs determines if the new elements is appended at the end or prepended at the beginning.
  4. Odd/Even is only defined for integers, so use a blue datatype.
0 Kudos
Message 30 of 40
(1,355 Views)