필터 지우기
필터 지우기

histogram without hist3 function

조회 수: 3 (최근 30일)
Kamil Tkacz
Kamil Tkacz 2015년 5월 13일
댓글: Kamil Tkacz 2015년 5월 13일
Hello folks
I have a problem with hist3 function. I need to draw histogram 3D without using hist function but i need to define some new function. I have 1000x2 matrix of random number from 1.5 to 3.5 range and i dont really know how to do this. I was thinking about using bar3 function fron this code:
data=[1 3 5 7 4 8 0 1 3];
If you want to distribute your data into 10 bins, you would create a new array of size 10:
histArray=zeros(1,10); % prealocate
x=0:1:9;
then, you would run a forloop to count how many times you encounter in a particular value:
for n=1:length(data)
histArray(1,data(n)+1)=histArray(1,data(n)+1)+1; % every time you meet the particular value, you add 1 into to corresponding bin
end
bar(histArray)
but i need this to use not with natural but with integral. I would be very gratefull for any help.
  댓글 수: 10
Walter Roberson
Walter Roberson 2015년 5월 13일
[uniqvals, ia, ib] = unique(x);
histArray = zeros(1, length(uniqvals));
for n=1:length(ib)
histArray(1,ib)=histArray(1,ib)+1;
end
bar(uniquevals, histArray);
Kamil Tkacz
Kamil Tkacz 2015년 5월 13일
Thanks man its working, but if i wanna to get 3D bar plot what should i do?

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

답변 (1개)

Image Analyst
Image Analyst 2015년 5월 13일
You can't use b directly as an index. You need to figure out what bin that the b value should be in. Like if b = 3.4423423423 do you want that in bin number 2, 8, or 42 or 300? If you want a bin for each unit integer range, then you can just use floor() or round() on the b values.
  댓글 수: 1
Kamil Tkacz
Kamil Tkacz 2015년 5월 13일
yea but when i take floor() or round() i will get only 1 2 or 3 but thats not a point

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

카테고리

Help CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by