Going back from cumsum for a matrix

3 次查看(过去 30 天)
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!

采纳的回答

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 CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by