Inverse/opposite of diff function?

13 ビュー (過去 30 日間)
Gregor Lees
Gregor Lees 2016 年 2 月 9 日
編集済み: Kristopher Anderson 2017 年 11 月 24 日
I have a 480x640 matrix and would like to perform the diff function on the elements but instead of subtracting the previous element I would like to add it.
I have tried using x(2:end) + x(1:end-1) Which return the right values but instead of returning a 479x640 matrix it returns a 1x307199 matrix. How can I change the function to give the 479x640 matrix.
Thanks in advance

採用された回答

Torsten
Torsten 2016 年 2 月 9 日
x(1:end-1,:) + x(2:end,:)
Best wishes
Torsten.
  1 件のコメント
Gregor Lees
Gregor Lees 2016 年 2 月 9 日
thank you

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

その他の回答 (1 件)

Kristopher Anderson
Kristopher Anderson 2017 年 11 月 24 日
編集済み: Kristopher Anderson 2017 年 11 月 24 日
The opposite of diff is cumsum.
Example:
>> A = randi([1,5],1,5)
A =
1 3 5 2 1
>> B = diff(A)
B =
2 2 -3 -1
>> C = cumsum([A(1) B])
C =
1 3 5 2 1

カテゴリ

Help Center および File ExchangeDescriptive Statistics and Visualization についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by