Klassieren und Zählen der Werte eines Arrays || Classifying and counting the values of an array
38 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Walter Roberson
2021 年 4 月 3 日
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
その他の回答 (1 件)
Dongyue
2022 年 11 月 22 日
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 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!