How to subtract ?
Afficher commentaires plus anciens
Its just a simple subtraction function in excel. Even It seems very simple in matlab. Still hitting my brain, but ....
A=[0 1 2 3 4 5 6];
B=12;

expected result of C: [11 9 6 2 -3 -9]
hints: 12-1 =11, 11-2=9, 9-3=6, 6-4=2, 2-5=-3, -3-6= -9
Réponse acceptée
Plus de réponses (3)
A=[0 1 2 3 4 5 6];
B = 12;
C = B-cumsum(A)
Can do this in a loop
B = 12;
A = [0 1 2 3 4 5 6];
C = 0*A;
C(1) = B(1) - A(1);
for ii = 2:numel(A)
C(ii) = C(ii-1) - A(ii);
end
C = C(2:end)
Or with a recursive filter
C = filter(-1,[1 -1],A,B);
C = C(2:end)
1 commentaire
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

