06-24-2014 04:00 AM
Hello!
We have an 1Darray with values and we want to rotate/shift the values (3 positions). But everytime it shifts we want to read the array.
For example : we have [1 2 3 4 5 6 7 8 9 10 ] and we want to shift it 3 positions like [10 9 8 1 2 3 4 5 6 7] we want to send this array, read it and then to rotate and read it every time until we get the first array.
Do we have to use loops or we can set it directly?
Any answers are welcome!
Thank You!
Solved! Go to Solution.
06-24-2014 04:15 AM
First off, rotating your array by three would result in [8 9 10 1 2 3 4 5 6 7].
What did you implement so far? What is it what you are struggling with exactly?
Yes, you will use loops to rotate, compare and iterate until your comparison to the original array is true.
Is this some kind of homework? The task by itself seems to be rather... strange as rotating until it matches the original array seems to be a Rube Goldberg task.
Norbert
06-24-2014 06:19 AM
Hi,
Yes we did a mistake in the example.
We tried it to rotate the array inside a for loop but what it does is to repeat the same rotation than replacing the new one.Which means that it gives [8 9 10 1 2 3 4 5 6 7] every time.
What we do is communicating with a dmx usb interface which means that every change in the array that we make we should read it and send it to our device.So shifting reading, sending and then again shifting reading, sending until we get the initial array.
Here is a part of our Vi with the rotate array function.
06-24-2014 06:25 AM
Why are you using these many for loops??
You can initialize visa once outside the loop and close it outside the loop?
I am still not understanding what you are trying to compare
06-24-2014 06:30 AM
Sorry, but your code is close to "unreadable" (not only to the fact that we only got a screenshot instead of the VI) and it of course does not perform to your liking.
From what i see is that your algorithm isn't build correctly. Can you draw something like a flow chart for your task?
This helps you in understanding the following points:
- Which code has to be included in a loop, which not?
- How many loops do you need overall? How often does it/they iterate (each)?
- Which data has to be modified each iteration, which not?
Regarding the last question: This defines if the data is passed into a shift register or kept in a simple input tunnel.
Norbert
06-24-2014 06:37 AM
Yes the loops are not necessary, we are just playing with the Vi.
We put the Visa inside the loop cause if we put it outside it will read only once and this is the final array and not the stages in between.Or maybe not?
In our case we have an array with 24positions and we have the initial array which is [ 255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] and we want to shift the array 7times with step 3 so next array that we want to send is [0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] and so on.
06-24-2014 06:45 AM - edited 06-24-2014 06:47 AM
Your Rotate
Normal rotate
06-24-2014 07:30 AM
Actually our Vi works but its not automated and we have to manually make changes every time. (We use sequences to repeat our steps).We posted the image cause our Vi is too big and complicated and we just repeat the same things.
Yes we know how this rotate function works but doesnt really solve our problem cause we need to do it 7 times and each time we make a rotation we need to send our array to our device.(these are RGB values).
06-24-2014 07:40 AM - edited 06-24-2014 07:40 AM
Why do people always insist on making things way more complicated than it needs to be...
06-24-2014 07:43 AM
@MAGI2 wrote:
Actually our Vi works but its not automated and we have to manually make changes every time. (We use sequences to repeat our steps).We posted the image cause our Vi is too big and complicated and we just repeat the same things.
Yes we know how this rotate function works but doesnt really solve our problem cause we need to do it 7 times and each time we make a rotation we need to send our array to our device.(these are RGB values).
We have to just loop the rotate array then why did you insist on changing the array value then?