Going back from cumsum for a matrix

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 comentario

valentino dardanoni
valentino dardanoni el 21 de Oct. de 2022
Thankyou David (and Walter). It works perfectly in my application.

Iniciar sesión para comentar.

 Respuesta aceptada

A=round(rand(100,100),4);
B=cumsum(A);
a=round([B(1,:);diff(B)],4);
isequal(A,a)
ans = logical
1

1 comentario

Walter Roberson
Walter Roberson el 21 de Oct. de 2022
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.)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Distribution Plots en Centro de ayuda y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by