フィルターのクリア

Going back from cumsum for a matrix

2 ビュー (過去 30 日間)
valentino dardanoni
valentino dardanoni 2022 年 10 月 21 日
コメント済み: valentino dardanoni 2022 年 10 月 21 日
Suppose I cumsum a matrix, say A=rand(3,3); B=cumsum(A).
Knowing B, how to I get back to A, in a reasonably efficient way, for a rather large B?
Thanks!
  1 件のコメント
valentino dardanoni
valentino dardanoni 2022 年 10 月 21 日
Thankyou David (and Walter). It works perfectly in my application.

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

採用された回答

David Hill
David Hill 2022 年 10 月 21 日
A=round(rand(100,100),4);
B=cumsum(A);
a=round([B(1,:);diff(B)],4);
isequal(A,a)
ans = logical
1
  1 件のコメント
Walter Roberson
Walter Roberson 2022 年 10 月 21 日
Right.
Key points here are the use of diff(), the duplication of the first entry, and the rounding or other way of comparing with tolerance for the cross-check (since you would need to deal with round-off errors.)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by