Effacer les filtres
Effacer les filtres

Correct histogram - with hist,histc ?

1 vue (au cours des 30 derniers jours)
x y
x y le 29 Nov 2014
Modifié(e) : x y le 29 Nov 2014
My textbook say,the correct histogram is that when the bars width is same in the histogram graph.
And show how to make correct histogram in ML for two type of data.
1.) when the classes are the same width
frekvenci = hist(data,k);
[frekvenci, reprezentatntclasses] = hist(data,k);
I tried in example,but I dont know is good way because I didnt get figure with graph ?!?
clear,clc
data = rand(100,1)*750;
k = 10;
pt = hist(data,k)
[pt, rt] = hist(data,k)
2.) when classes isnt the same width
ht = [. .. ..] %binranges
frekvencie = histc(data,ht)
width = ht(2:end) - ht(1:end-1) %width classes
nor = frekvencie(1:end-1)./width %normaziation fkrev.classes
bar(ht,nor,'histc')
in concrate example I tried:
clear,clc
data = rand(100,1)*750;
ht = [0 100 200 300 500 ];
pt = histc(data,ht)
sum(pt)
sirky = ht(2:end) - ht(1:end-1)
upt = pt(1:end-1)./sirky %here I get dimension error ?!? how can I solve this error
bar(ht,upt,'histc')

Réponses (1)

x y
x y le 29 Nov 2014
Modifié(e) : x y le 29 Nov 2014
I found other example,that was:
ht = [170 290 350 410 470 530 710]
pt = [ 8 12 11 8 5 6]
sirky = ht(2:end) - ht(1:end-1)
upt = pt./sirky
bar(ht, [upt 0], 'histc')
and now what I want,it is good ?
ht = [0 100 200 300 500 ];
pt = histc(data,ht)
pt = pt'
length(pt)
sirky = ht(2:end) - ht(1:end-1)
upt = pt(1:end-1)./sirky
bar(ht,[upt 0],'histc') % this [upt 0] is always there are this 0 ??

Community Treasure Hunt

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

Start Hunting!

Translated by