Subtracting elements in an array

1 vue (au cours des 30 derniers jours)
Nikolas Spiliopoulos
Nikolas Spiliopoulos le 21 Jan 2017
Commenté : Star Strider le 22 Jan 2017
hi there,
I have an array lets say
A=[10 9 10; 1 2 3; 4 5 6]
How can create an array like this?
B=[10-1 9-2 10-3;10-1-4 9-2-5 10-3-6]
thanks in advance!
Nikolas

Réponse acceptée

Star Strider
Star Strider le 21 Jan 2017
Modifié(e) : Star Strider le 21 Jan 2017
If I understand correctly what you are asking, this will work:
A=[10 9 10; 1 2 3; 4 5 6]
B = cumsum(-A(2:end,:))+A(1,:)
A =
10 9 10
1 2 3
4 5 6
B =
9 7 7
5 2 1
  9 commentaires
Nikolas Spiliopoulos
Nikolas Spiliopoulos le 22 Jan 2017
ok got it, it works! thanks again mate..!!!
Star Strider
Star Strider le 22 Jan 2017
Our pleasure!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by