How to sum all instances of a value across a variable?
    3 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
    Louisa Thomas
 am 15 Jan. 2018
  
    
    
    
    
    Kommentiert: Louisa Thomas
 am 15 Jan. 2018
            My variable follows this format
a =  [1 2 2 1]
etc.
So all of the values are either 1, or 2.
How do I sum all of the instances of the number 1 across this variable?
1 Kommentar
  Jan
      
      
 am 15 Jan. 2018
				Is this a homework question? If so, what have you tried so far? Do you want to solve it with a loop or with the efficient builtin method unique and histcounts?
As usual I could offer a method based on RunLength. After I have suggested it a hundred of times in the forum already, I think about changing my nick name to "JanLength".
Akzeptierte Antwort
Weitere Antworten (0)
Siehe auch
Kategorien
				Mehr zu Data Type Identification finden Sie in Help Center und File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

