i have an array about 252 x 252 cells from the excel file, it have many values from 1 to 256, so i want to count how many times each of value appear in this array like frequency and cummulative? example ( just a small array):
and the result like as :
i did it in excel but i don't know how to do it in Matlab.
Thank you so much with any help!!

 채택된 답변

Star Strider
Star Strider 2014년 5월 6일
편집: Star Strider 2014년 5월 6일

1 개 추천

It is impossible to get the data out of your figure file, but I downloaded the subset of data you posted earlier. I’m including it here for others to work with.
To get counts of the various values, use histc, and to plot them, use bar:
A = [52 53 51 52 55 59 61 61 61 59 56 51 54 52 49 49 55 61 67 68 69 67 63 56 49 46 44 48 58 66 77 74 71 70 67 61 45 44 45 52 63 72 78 74 69 65 62 57 45 46 48 55 65 73 76 72 65 59 55 51 50 51 52 54 59 63 66 63 59 54 50 47 49 51 50 49 48 48 51 51 50 49 47 44 41 42 42 41 40 39 39 41 43 43 40 38 35 33 33 35 37 37 35 37 37 35 32 30 35 30 29 32 36 38 36 36 34 29 26 26 41 37 31 27 30 36 36 36 34 29 23 23 39 35 30 25 27 32 35 35 34 29 24 24 32 30 26 22 22 26 34 35 34 30 26 25 24 25 25 22 22 23 35 36 35 32 29 28 22 26 31 31 30 30 38 38 36 33 31 31 26 34 43 45 42 40 40 38 35 32 31 31 30 40 51 53 49 45 40 37 32 29 28 30 31 41 53 55 49 45 40 35 30 26 26 28 37 44 49 48 44 42 36 37 32 25 21 25 41 47 50 45 39 36 41 42 37 29 25 29 47 53 54 47 39 36 47 47 43 35 31 34 51 59 59 51 44 43 48 49 45 38 35 39 54 61 59 50 44 44 46 48 45 38 37 42 58 61 54 42 38 40 45 47 44 38 37 42 64 63 51 38 36 40 48 49 46 38 36 40 69 66 53 40 39 45 51 52 48 39 36 39 70 63 51 43 44 49 54 48 41 38 39 43 67 61 52 45 44 46 50 47 43 43 48 53];
Amm = [min(A) max(A)]; % Find range of data
bins = Amm(1):Amm(2); % Create bin locatins
c = histc(A, bins); % Generate histogram (frequency) counts
cc = cumsum(c); % Cumulative counts in bin order
figure(1) % Plot histogram
bar(bins, c)

댓글 수: 4

cuong nguyen
cuong nguyen 2014년 5월 6일
thanks so much!
Star Strider
Star Strider 2014년 5월 6일
My pleasure!
cuong nguyen
cuong nguyen 2014년 5월 6일
dear!
i so sorry but the function histc is not good for me now, i don't know why, it should be return back an array 2 x 256, but it not! Can i have your email? may be i can send my data for you to hlep me?
thanks!
The histc function in the code I posted is working as it should. It counts the number of occurrences of a particular range of values (here, one for each value present in A). Note that hist and histc are similar by behave slightly differently.
You want it to count every occurrence of every value (in my code, the bin vector is created automatically to include all integers in the range of min(A) to max(A)), and that is what it does. Note that in the bar plot, I plotted bar(bins, c), indicating that bins is the independent (x) variable, and the histogram counts vector (c) the dependent variable.
Note that hist and histc are different. If you do not specify the bin ranges as I did, hist creates the bin locations on its own, which may not be the bin locations you want. If you want to create the (2x256) array, call it H for instance, and define it as:
H = [c; bins];
That should be the array you want. It replicates the array that hist would return.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Histograms에 대해 자세히 알아보기

질문:

2014년 5월 6일

댓글:

2014년 5월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by