calculating sum of integers

4 ビュー (過去 30 日間)
Aldrich Dias
Aldrich Dias 2021 年 2 月 22 日
コメント済み: Aldrich Dias 2021 年 2 月 22 日
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?

採用された回答

KSSV
KSSV 2021 年 2 月 22 日
編集済み: KSSV 2021 年 2 月 22 日
n = 123456789;
iwant = sum(num2str(n) - '0')
  5 件のコメント
Aldrich Dias
Aldrich Dias 2021 年 2 月 22 日
hmm i converted it then do I do prod(n)? or prod(n,1:2)?
Aldrich Dias
Aldrich Dias 2021 年 2 月 22 日
i get it now
thank you

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by