LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Reverse ID Array (using Shift Registers)

Solved!
Go to solution

Hello guys,

Could someone give me some hints about how to write a program that produces an output array whose elements are in the reverse ordered to that of the input array, using shift register in the For Loop without using the built-in function Reverse ID array.

I tried to write it, but rather confusing.  there are the suggested icons that can be used in this program: Initialize Array, Array Size and Replace Array Subset.

 

Best,

0 Kudos
Message 1 of 17
(5,596 Views)

Pointless homework problems...

 

I would use a FOR loop.  Use the Array Size to tell the loop how many times to iterate (wire the output the N).  Inside the loop, use Index Array to get the N-i element.  This will get the last, then the next from last, etc element each iteration.  The output of the Index Array gets autoindexed out of the FOR loop.



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 17
(5,575 Views)

Better get the N-i-1st element… 😄

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 3 of 17
(5,569 Views)

@GerdW wrote:

Better get the N-i-1st element… 😄


I was leaving that for the OP to figure out.  Have to make the students think a little bit.Smiley Tongue



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 4 of 17
(5,558 Views)

One more suggestion: use an autoindexing input tunnel of a For loop to get the single elements of the array. Build a new array in the loop using BuildArray with a shift register...

You will learn about autoindexing and how to build arrays!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 17
(5,538 Views)

Avral wrote:

Could someone give me some hints about how to write a program that produces an output array whose elements are in the reverse ordered to that of the input array, using shift register in the For Loop without using the built-in function Reverse ID array.

 


This is an excellent exercise to learn about array manipulations, shift registers, and FOR loops. I guess you have all weekend to solve it, so I encourage you to just try. As a bonus, try to find at least three different ways to do it. 😄

 

The nice thing is also that you can immediately compare it with the output of the "reverse array" primitive to ensure that your solution is correct.

 


@Avral wrote:

there are the suggested icons that can be used in this program: Initialize Array, Array Size and Replace Array Subset.

 


No, you don't need "initialize array". You can re-use the input array. Most solutions I can think of don't need it. And if you use "replace array subset", you don't need array size. Is the "Shift register" mandatory? You don't really need it.

0 Kudos
Message 6 of 17
(5,533 Views)

Try to find a solution that does it in half the number of iterations. (And if the number of elements is odd, you don't even need to touch the central element for one fewer iteration). 😄

 

(look for "logical shift", "in place element structure (array index/replace elements)", "swap values", etc.)

0 Kudos
Message 7 of 17
(5,520 Views)

Hi Avral,

 

Plz check the image. Are you looking the same functionality?

Download All
0 Kudos
Message 8 of 17
(5,466 Views)

@User002_Automation wrote:

 

Plz check the image. Are you looking the same functionality?


While the functionality seems correct, the code is overly complicated. Using delete from array in a tight loop is pointless and unnecessary. Why would you need to thinly slice up an array just to rebuild it elsewhere? You know that the size changes by 1 with every iteration of the loop, so why would you need to measure it? Try again!

0 Kudos
Message 9 of 17
(5,452 Views)

Hello 

 

0 Kudos
Message 10 of 17
(5,442 Views)