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 件のコメント
Matt J
Matt J 2020 年 9 月 8 日
B=ifun(T*fun(A));
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
  1 件のコメント
dani elias
dani elias 2020 年 9 月 8 日
Thank you. I do appreciate your contributions.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by