Klassieren und Zählen der Werte eines Arrays || Classifying and counting the values of an array
    11 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
    Patrick Benz
 am 31 Mär. 2021
  
    
    
    
    
    Beantwortet: Dongyue
    
 am 22 Nov. 2022
            Hallo zusammen,
ich möchte die EInträge eines Arrays klassieren und zählen. Ich habe ein 10x2 array, welches ungefähr so aussieht:
400     0
396     0
392     1
400     0
396     1
400     1
das klassieren schaffe ich mit
sigma(:,1)=unique(Lasthorizonte(:,1));
wie schaffe ich es jetzt aber in sigma(:,2) die Anzahl der jeweiligen Werte einzutragen? Versucht habe ich es mit
sigma(:,2)=sum(Lasthorizonte==1,2);
da erhalte ich allerdings die Fehlermeldung "Unable to perform assignment because the size of the left side is 3-by-1 and the size of the right side is 12-by-1.".
Ziel wäre es, dass ich in sigma (:,2) die Anzahl der "1" und in sigma(:,3) die Anzahl der "0" je Zahl in der ersten Spalte erhalte.
0 Kommentare
Akzeptierte Antwort
  Walter Roberson
      
      
 am 3 Apr. 2021
        Lasthorizonte = [
    400     0
    396     0
    392     1
    400     0
    396     1
    400     1];
[sigma, ~, uidx] = unique(Lasthorizonte(:,1));
counts = accumarray([uidx, 2-Lasthorizonte(:,2)], 1);
sigma = [sigma, counts];
sigma
Weitere Antworten (1)
  Dongyue
    
 am 22 Nov. 2022
        LoadHorizons = [400 0;
396 0;
392 1;
400 0;
396 1;
400 1];
tbl = tabulate(categorical(LoadHorizons(:,1)));
sigma = cell2table(tbl,'VariableNames', ...
    {'Value','Count','Percent'})
0 Kommentare
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!