calculating sum of integers

4 Ansichten (letzte 30 Tage)
Aldrich Dias
Aldrich Dias am 22 Feb. 2021
Kommentiert: Aldrich Dias am 22 Feb. 2021
How to find the sum sum of a intiger for examples if i had an input like 123456789 and the sum of it will be 1+2+3+4+5+6+7+8+9. Is there a special function for this?

Akzeptierte Antwort

KSSV
KSSV am 22 Feb. 2021
Bearbeitet: KSSV am 22 Feb. 2021
n = 123456789;
iwant = sum(num2str(n) - '0')
  5 Kommentare
Aldrich Dias
Aldrich Dias am 22 Feb. 2021
hmm i converted it then do I do prod(n)? or prod(n,1:2)?
Aldrich Dias
Aldrich Dias am 22 Feb. 2021
i get it now
thank you

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by