Not able to get count of each elements in array itself
1 回表示 (過去 30 日間)
古いコメントを表示
Scott Tehelson
2020 年 6 月 30 日
コメント済み: Scott Tehelson
2020 年 6 月 30 日
I am having this array..x=[ 1 2 3 1 2]
Now I want to replace it with count of the corresponding elements..here x should get modified to x=[2 2 1 2 2]
By using hist(x, unique(x)) I am able to do it but it gives the count for unique elements. I want the result to have the number of elements.
please help!
0 件のコメント
採用された回答
Gaganjyoti Baishya
2020 年 6 月 30 日
Hi Scott,
Instead of using the histc function, you can use the grouptransform function to get the count of all elements int the array.
x = [1 2 3 1 2];
x = [1 2 3 1 2]';
x = grouptransform(x,x,@numel);
x contains the required array.
その他の回答 (1 件)
参考
カテゴリ
Help Center および File Exchange で Multidimensional Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!