How to counting frequency of a value occurence in a matrix?
9 ビュー (過去 30 日間)
古いコメントを表示
Dear All,
I have a vector which values are 1:31. I would like to calculate the frequency of occurence these values in different matrixes. I tried the following way:
a = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31];
out = [a, histc(x(:),a)];
but I got the following error:
Error using horzcat
Dimensions of matrices being concatenated are not consistent.
Some value of a does not exist in the matrix thust I cannot use
unique(x)
fuction. Can someone suggest me a solution?
0 件のコメント
回答 (1 件)
Guillaume
2019 年 1 月 16 日
Since you're passing a column vector to histc (X(:)), the output is going to be a column vector. Hence you're trying to concatenate a row vector (a) with a column vector. Indeed the dimension of matrices being concatenated are never going to be consistent. The easiest is to transpose a.
Note that the way you create a is overly complicated. You must like typing!
a = 1:31;
out = [a', histc(X(:), a)]
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!