How to shift a cell in a matrix by desired number?

I have a matrix which has 8x8x8 dimensions. In every cell there are values like one and zeros. here is an example of my values.
A =
1 1 0 0 0 0 0 0
1 1 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1
like this A i have 7 more layers so it is an 8x8x8
So i want to shift every values in my matrix to the right like 7 or 15 times. In the end of the row values should pass the next coloumn and the end of the matrix values should return to the begining. values are not passing to the other layers every layer are shifting in its own. so none of the values are getting lost in a matrix just shifting. for example if i shift values to the right like 7 times, i should get this:
A1 =
0 0 0 0 0 0 1 1
1 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
i tried circshift but i didnt get anything. i hope somebody can help, thanks.

답변 (2개)

KSSV
KSSV 2021년 9월 8일

1 개 추천

Read about circshift.
Looking more into @KSSV's suggestion, maybe circshift will work for you, if you reshape A first:
A = [1 1 0 0; 1 1 0 0; 0 0 0 0; 0 0 0 1]
A = 4×4
1 1 0 0 1 1 0 0 0 0 0 0 0 0 0 1
[m,n] = size(A); % remember for later
B = reshape(A,1,numel(A))
B = 1×16
1 1 0 0 1 1 0 0 0 0 0 0 0 0 0 1
B2 = circshift(B,2)
B2 = 1×16
0 1 1 1 0 0 1 1 0 0 0 0 0 0 0 0
A2 = reshape(B2,m,n)'
A2 = 4×4
0 1 1 1 0 0 1 1 0 0 0 0 0 0 0 0
I'm not willing to look into if or how that works in a 3D-matrix case, but you can take it from here, I think.

댓글 수: 1

it doesnt matter i can apply it each layer one by one but i need it to apply on at least 8x8 matrix. in example i just put some ones to show what kind of shift i need. in normal conditions each cell have a value, i need to shift in 8x8 matrix, but if it is not possible i can reshape my matrixes like you suggested and shift them.
thanks

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

질문:

2021년 9월 8일

댓글:

2021년 9월 8일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by