Borrar filtros
Borrar filtros

sum in matlab coding

2 visualizaciones (últimos 30 días)
ali hassan
ali hassan el 12 de Feb. de 2022
Editada: DGM el 12 de Feb. de 2022
what is the difference between
sum(a(1):a(3)) and sum(a(1:3))?

Respuesta aceptada

DGM
DGM el 12 de Feb. de 2022
Editada: DGM el 12 de Feb. de 2022
The first case is summing a linear increasing series between two values stored in a vector. The second is the sum of a subvector within a vector.
a = [5 -10 15 -20]
a = 1×4
5 -10 15 -20
a(1):a(3) % linear vector from 5 to 20 in steps of 1
ans = 1×11
5 6 7 8 9 10 11 12 13 14 15
a(1:3) % elements 1 through 3 of the vector a
ans = 1×3
5 -10 15
sum(a(1):a(3))
ans = 110
sum(a(1:3))
ans = 10

Más respuestas (0)

Categorías

Más información sobre Numeric Types en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by