How can I plot the column-wise frequency of different elements for an mxn array?

2 ビュー (過去 30 日間)
Bee
Bee 2016 年 1 月 13 日
コメント済み: Star Strider 2016 年 1 月 14 日
Hello, I have an mxn array of numbers (integers or decimal numbers). I can use hist function separately for each column to find out frequency of each elements, for example: hist on each column gives output like 10 1's, 15 2's 25 7's in column 1; 25 2's, 25 3's in column 2; etc. Now I want to plot the histograms in a 3D plot, so that x axis = m, y axis = n, z axis = frequency of each element.
It seems very plain and simple, but somehow I am really struggling with this. Any help is greatly appreciated. Thanks for your time.
  1 件のコメント
Bee
Bee 2016 年 1 月 13 日
I wanted to ask a question and confused it with the newsgroup messaging, so I posted a message in the newsgroup. Was wondering if it is illegal to ask the same question in the Newsgroup and MATLAB Answers.

サインインしてコメントする。

採用された回答

Star Strider
Star Strider 2016 年 1 月 14 日
I would use histc (or histcounts) and plot the results with bar3:
M = randi(3, 15, 6); % Create Data
binrng = 0:4; % Set Bin Ranges
counts = histc(M, binrng); % Histogram Counts
figure(1)
bar3(binrng, counts) % Plot
xlabel('Columns')
ylabel('Rows')
zlabel('Frequency')
  2 件のコメント
Bee
Bee 2016 年 1 月 14 日
Thank you! Thank you! Thank you! I only changed binrng = 1:3 instead of 0:4 for your example, and that gave me what I want. Thank you soooo much!
Star Strider
Star Strider 2016 年 1 月 14 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by