How to shift a cell in a matrix by desired number?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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.
0 comentarios
Respuestas (2)
Paul Kaufmann
el 8 de Sept. de 2021
A = [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))
B2 = circshift(B,2)
A2 = reshape(B2,m,n)'
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.
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!