Manipulating an array with an octave circcift / matlab
1) I am trying to move an array (outer cells) to the first and last cell inward at the same time. Here's an internal animation of what I am trying to do with an array internal animation . As you can see, the outer cells move inward (from the ends) at the same time
Here's a picture, but the animation shows it much better, note that the array can have an even or odd number of cells
Inner rotation steps
1 2 3 4 5 6 7
4 1 2 3 6 7 5
3 4 1 2 7 5 6
2) I am trying to move the middle cells of an array outward using the circshift method (which I think is the fastest) at the same time. Here's an external animation of what I am trying to do external animation . As you can see, the middle of the waveform moves outward (left and right) at the same time.
Here's a picture, but the animation shows it much better, note that the array can have an even or odd number of cells
Outer rotation steps
1 2 3 4 5 6 7
2 3 4 1 7 5 6
3 4 1 2 6 5 7
Example: inward
a = (1:7)
y=circshift(A,[0 -2]) %shift end of array inward
3 4 5 6 7 1 2
a = (1:7)
y=circshift(A,[0 2]) %shift beginning of array inward
6 7 1 2 3 4 5
Not sure how to make middle cells move outward using circular movement or outer cells moving inward at the same time
I'm not sure how to start a circular motion from the center and move the array outward / inward to get this effect.
Please note that I am not trying to get this equation. I am just trying to get the arrays to move in the same way. I am using octave 3.8.1 which is Matlab compatible.
source to share
how to build new indexes instead of using circshift:
A = 1:7; halfLen = ceil(length(A)/2); % or use ceil to idcsOutward = [2:halfLen,1,length(A),(halfLen+1):(length(A)-1)]; B1 = A(idcsOutward) B2 = B1(idcsOutward) % and inward: idcsInward = [halfLen,1:(halfLen-1),(halfLen+2):length(A),halfLen+1]; C1 = A(idcsInward) C2 = C1(idcsInward)
Result:
B1 = 2 3 4 1 7 5 6 B2 = 3 4 1 2 6 7 5 C1 = 4 1 2 3 6 7 5 C2 = 3 4 1 2 7 5 6
source to share