필터 지우기
필터 지우기

shifting of matrix elements

조회 수: 3 (최근 30일)
sadiqa ilyas
sadiqa ilyas 2020년 2월 29일
댓글: sadiqa ilyas 2020년 3월 1일
hi,Can i divide the matrix into layers ,outer layer(boundary elements)then second layer and so on.
for example
original matrix is
1 2 3 4 5 6 7 8
9 10 11 12 13 14 15 16
17 18 19 20 21 22 23 24
25 26 27 28 29 30 31 32
33 34 35 36 37 38 39 40
41 42 43 44 45 46 47 48
49 50 51 52 53 54 55 56
57 58 59 60 61 62 63 64
After one bit right shift of outside boundary and inside layers (its like contour)
9 1 2 3 4 5 6 7
17 18 10 11 12 13 14 8
25 26 27 19 20 21 15 16
33 34 35 36 28 22 23 24
41 42 43 37 29 30 31 32
49 50 44 45 46 38 39 40
57 51 52 53 54 55 47 48
58 59 60 61 62 63 64 56

채택된 답변

David Hill
David Hill 2020년 2월 29일
Not sure if there is an easier way, but this does it for you.
function M=matShift(M)
x=size(M,1);
for k=1:floor(x/2)
z=x-2*(k-1)-1;
y=circshift([M(k,k:end-k),M(k:end-k,end-k+1)',M(end-k+1,end-k+1:-1:k+1),M(end-k+1:-1:k+1,k)'],1);
M(k,k:end-k)=y(1:z);
M(k:end-k,end-k+1)=y(z+1:2*z);
M(end-k+1,end-k+1:-1:k+1)=y(2*z+1:3*z);
M(end-k+1:-1:k+1,k)=y(3*z+1:4*z);
end
  댓글 수: 4
David Hill
David Hill 2020년 2월 29일
Just assign to a different variable at beginning
m=M;
sadiqa ilyas
sadiqa ilyas 2020년 3월 1일
thanks

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by