How to count a specific value from column to column

Hey
Maybe a simple question. But if I have a vector lets say 15x1 vector like:
[1 1 1 0 1 0 0 1 0 0 1 0 1 0 1]
Now I want to count the number 1 in range of 5 columns so I get a new vector:
[4 1 3]
Anyway to do that?

 採用された回答

madhan ravi
madhan ravi 2019 年 1 月 3 日
編集済み: madhan ravi 2019 年 1 月 3 日

0 投票

a=[1 1 1 0 1 0 0 1 0 0 1 0 1 0 1];
Result=sum(reshape(a',5,[]))
Gives:
Result =
4 1 3

2 件のコメント

madhan ravi
madhan ravi 2019 年 1 月 3 日
Jonas Damsbo's comment moved here:
Thank you! Thats work!
madhan ravi
madhan ravi 2019 年 1 月 3 日
Anytime :)

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMathematics についてさらに検索

質問済み:

2019 年 1 月 3 日

編集済み:

2019 年 1 月 3 日

Community Treasure Hunt

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

Start Hunting!

Translated by