Product of elementwise differences

1 回表示 (過去 30 日間)
Chethan S
Chethan S 2011 年 5 月 8 日
As a part of a large function in my MATLAB code I have to calculate difference between elements of matrices and sum them up in a special way. Let me illustrate my case with sample matrices:
1 2 3 4
9 10 11 12
and
5 6 7 8
13 14 15 16
My calculations goes as follows:(Zeroes appear due to padding)
(1-2)(5-6)+(2-3)(6-7)+(3-4)(7-8)+(4-0)(8-0): This replaces 1 in initial matrix.
(2-3)(6-7)+(3-4)(7-8)+(4-0)(8-0)+(0-0)(0-0): This replaces 2 in initial matrix.
(3-4)(7-8)+(4-0)(8-0)+(0-0)(0-0)+(0-0)(0-0): This replaces 3 in initial matrix.
........
Coming to second row of matrices:
(9-10)(13-14)+(10-11)(14-15)+(11-12)(15-16)+(12-0)(16-0): This replaces 9 in initial matrix.
(10-11)(14-15)+(11-12)(15-16)+(12-0)(16-0)+(0-0)(0-0): This replaces 10 in initial matrix.
.........
As an inexperienced programmer I am finding this task really hard. Can someone please help me?

採用された回答

Walter Roberson
Walter Roberson 2011 年 5 月 8 日
Not much too this one.
fliplr(cumsum(diff([zeros(size(A,1)),fliplr(A)],1,2) .* diff([zeros(size(B,1)),fliplr(B)],1,2),2))

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by