how to have a vector that counts how many repetitive numbers there is in another vector?
4 ビュー (過去 30 日間)
古いコメントを表示
So i have a vector with 100 numbers. And those numbers only goes until 51.
For example A = [ 50 49 32 21 50 38 41 2 46.....]
And what i want is a vector B that has 51 numbers and tells me for example how many 1's there is in vector A, and how many 2's there's in the vector and so on.
Thank you
採用された回答
madhan ravi
2018 年 8 月 17 日
Maybe try this example:
A = [1 2 3 3 4 5 1]
u = unique(A)
Expected_result = histc(A,u)
0 件のコメント
その他の回答 (2 件)
Image Analyst
2018 年 8 月 17 日
Do you mean the histogram?
% Make a vector with 1000 numbers in the range 1 - 51.
A = randi(51, 1, 1000)
% count frequency of each number
histObj = histogram(A)
grid on;
title('Histogram of A', 'FontSize', 17);
xlabel('A Value', 'FontSize', 17);
ylabel('Count', 'FontSize', 17);
% Get counts.
counts = histObj.Values
% Get bin edges.
edges = histObj.BinEdges
% Get bin centers.
binCenters = (edges(1:end-1) + edges(2:end)) / 2

0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Histograms についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!