hi every one ,
    7 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
    mina massoud
 am 7 Mai 2019
  
    
    
    
    
    Bearbeitet: Adam Danz
    
      
 am 13 Mai 2019
            A=[ 1 1 1 2 2 3 3 3 1 1 4 4 4 2 2 3 3 3 4 3 ] 
how can i count the number of 1 and 2 and 3 and 4 in the row vector 
thank u 
0 Kommentare
Akzeptierte Antwort
  Alex Mcaulley
      
 am 7 Mai 2019
        sum(A==1) % or sum(A==2)...
1 Kommentar
  Adam Danz
    
      
 am 9 Mai 2019
				
      Bearbeitet: Adam Danz
    
      
 am 9 Mai 2019
  
			Note that you'll need to calculate the unique values in A and then loop through each of them in order to use this method. 
Aunq = unique(A); 
count = zeros(size(Aunq));
for i = 1:length(Aunq)
    count(i) = sum(A==Aunq(i)):
end
...which is all done in the one line of code I propsed using histcounts().  
Weitere Antworten (1)
  Adam Danz
    
      
 am 7 Mai 2019
        
      Bearbeitet: Adam Danz
    
      
 am 13 Mai 2019
  
      A=[ 1 1 1 2 2 3 3 3 1 1 4 4 4 2 2 3 3 3 4 3 ];
counts = histcounts(A,[unique(A),max(A)+1]); 
Result
list = table(unique(A)', counts', 'VariableNames', {'Number', 'Count'}); 
list =
    4×2 table
    Number    Count
    ______    _____
      1         5  
      2         4  
      3         7  
      4         4 
0 Kommentare
Siehe auch
Kategorien
				Mehr zu Data Distribution Plots 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!


