What can be a reverse permutation formula of n*m matrix

조회 수: 1 (최근 30일)
dani elias
dani elias 2020년 9월 7일
댓글: dani elias 2020년 9월 8일
The first row remain as it is, but from the second to the end it changed as shown below: Given A as original matrix, B the result matrix. the first row at B remain as it was in A, but at second row, the first element is obtained After add the first element at row above and it's last element in corresponding row, such as B[2,1]=A[1,1]+A[2,4] which is 9=5+4. But the second element at row two is B[2,2]=A[2,1]+A[1,2] which is 13=10+3. So 13=11+2,4=3+1, again for next row B[3,1]=8+10, B[3,2]= 6+11 etc..
A=[4 3 2 1;10 11 3 5; 6 4 7 8; 9 10 40 5]
B=[ 4 3 2 1; 9 13 13 4; 18 16 7 12; 11 23 17 48].
I need the reverse formula to its original matrix.. Assume Matrix A is of size 256*256 or 512*512
  댓글 수: 1
Matt J
Matt J 2020년 9월 8일
I think you have incorrect entries in B(3:4,2). I think the real B matrix should be,
B =
4 3 2 1
9 13 13 4
18 17 7 12
11 13 17 48

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

채택된 답변

Matt J
Matt J 2020년 9월 8일
편집: Matt J 2020년 9월 8일
Assuming A and B are always square,
n=length(A);
E=speye(n);
S=circshift(E,[1,0]);
T=kron(S,E)+kron(E,S);
T(1:n,1:n)=E;
T(1:n,n+1:end)=0;
fun=@(Z) reshape(Z.',[],1);
ifun=@(Z) reshape(Z,n,n).';
A=ifun(T\fun(B))
  댓글 수: 5
dani elias
dani elias 2020년 9월 8일
Thank you. I do appreciate.

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

추가 답변 (1개)

Matt J
Matt J 2020년 9월 8일
This version is also quite fast - maybe even faster than my other, fully vectorized answer.
n=length(A);
%% Forward
tic;
B=A;
B(2:end,:)=A(1:end-1,:)+circshift(A(2:end,:),[0,1]);
toc
%% Inverse
A=B;
tic
for i=2:n
A(i,:)=circshift(A(i,:)-A(i-1,:),[0,-1]);
end
toc

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by