How to count a specific value from column to column

1 vue (au cours des 30 derniers jours)
Jonas Damsbo
Jonas Damsbo le 3 Jan 2019
Modifié(e) : madhan ravi le 3 Jan 2019
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?

Réponse acceptée

madhan ravi
madhan ravi le 3 Jan 2019
Modifié(e) : madhan ravi le 3 Jan 2019
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 commentaires
madhan ravi
madhan ravi le 3 Jan 2019
Jonas Damsbo's comment moved here:
Thank you! Thats work!
madhan ravi
madhan ravi le 3 Jan 2019
Anytime :)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by