How can I plot histogram using b as x value and k as bin values? plotting histogram error line 16
古いコメントを表示
load sizes2.txt
results= sizes2(:,1)
n=size(sizes2,1) % num of rows
a=sizes2(:,:)
b=sort(a)
y=log10(n)
k= 1+3.322*y % is suggested number of class intervals and n is the number of values in the data set
fprintf('The suggested number of class intervals is %d\n', k );
x=range(b)
w=x/k % width of class intervals
fprintf('The suggested number of class intervals is %d\n', w)
k=8
hist(b,k)
Thank you
7 件のコメント
rathod ujjval rameshbhai
2015 年 9 月 1 日
i think k should be integer
Jackie
2015 年 9 月 1 日
Jackie
2015 年 9 月 1 日
dpb
2015 年 9 月 1 日
nbins ~= integer doesn't cause the above error; it does change the binning calculation.
Need to attach your data to test to see what might be going on here.
Jackie
2015 年 9 月 1 日
dpb
2015 年 9 月 1 日
I can't reproduce an error; I would simplify quite a lot, but I get no error...I did just paste the data from the text file into the command window as variable sizes. Whatever is causing the above error is somewhere else than in the above.
>> n=length(sizes);
>> k=1+3.322*log10(n) % without rounding
k =
8.3130
>> k1=fix(k); % truncate; use round() if to nearest integer
>> n=hist(sizes,k) % with the non-integer value
n =
58 51 27 11 4 4 2 2
>> m=hist(sizes,k1) % and the integer version...
m =
58 56 22 14 2 3 2 2
>> sum(m)==sum(n) % both get all the elements
ans =
1
>> hist(sort(sizes),k1) % and to so you don't need sort()
>> o=hist(sort(sizes),k1)
o =
58 56 22 14 2 3 2 2
>>
I didn't delve into the code of hist to see just exactly what it's doing with the non-integer bins; clearly it also truncated to the integer number but it did modify the binning as can be seen comparing the two outputs.
But, it doesn't cause an indexing error (and it doesn't appear to be the problem in your case as you still got an error)
Oh; you haven't by chance inadvertently created a variable hist, have you? Try
clear hist
and then try again...or, to see before clear try
which hist
Jackie
2015 年 9 月 2 日
回答 (1 件)
Image Analyst
2015 年 9 月 2 日
0 投票
Why not just call histcounts() and then bar()?
カテゴリ
ヘルプ センター および File Exchange で Data Distribution Plots についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!