What can be a reverse permutation formula of n*m matrix
1 回表示 (過去 30 日間)
古いコメントを表示
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
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
採用された回答
その他の回答 (1 件)
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 Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!