histogram without hist3 function

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 Commenti

Adrian Lukasik comments,
"Yes, I have the same problem. Is there anybody who can help? I will appreciate any kind of help. Thanks"
I do not understand the part of the question about "not with natural but with integral" ? Do you mean you need to be able to use non-positive integers? If so then add min() of the array to the array, to move everything to start from 0.
I mean that i havent only numbers eg a=[1 2 3 4] but a=[1.32 2.23 3.23] etc
In that situation you need to specify how wide your bins are. For example is 2.23 to be in the same bin as 2.35 ?
The hist3() function is a 2D histogram (in spite of its name). What are the two axes you want? Do you want to count the number of times a number in column 1 occurs next to a number in column 2? Or you just want a 1-D (normal/typical) histogram but you want the bars to appear like 3-D rectangular blocks in the graphical rendering of the bar chart? Like a perspective rendering of like a downtown with a bunch of tall buildings?
Kamil Tkacz
Kamil Tkacz il 13 Mag 2015
Modificato: Walter Roberson il 13 Mag 2015
I have b matrix something like that:
2,02085330994252 3,37335163967821
2,01432967580118 2,87956246361789
1,98888580125719 2,94872963058246
2,03175350110794 3,18778402658568
2,01985630417869 2,94065902167881
1,99608181014680 3,04200865360027
1,97983466806013 2,87338363304051
1,95787777864383 2,90438687939339
2,06812779458210 3,09865021742356
1,97168460967792 3,42180651642130
2,01646573278722 2,91840563735020
2,04533414992640 2,87811917742869
2,03652910042965 3,02624951544694
2,09874470242695 3,06648117997219
1,98843495519092 2,94899138948997
and i wanna to draw histogram without using hist function. I trying to write some code but i've got error that "index must be a positive integer or logical" and i dont know what i should do with that.
x = (b(:,1));
y = (b(:,2));
histArray=zeros(1,4);
for n=1:length(b)
histArray(1,b=histArray(1,b)+1;
end
bar(histArray)
You need to define how wide you want your bins to be.
OK so how can i do that?
[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);
Thanks man its working, but if i wanna to get 3D bar plot what should i do?

Accedi per commentare.

Risposte (1)

Image Analyst
Image Analyst il 13 Mag 2015

0 voti

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 Commento

yea but when i take floor() or round() i will get only 1 2 or 3 but thats not a point

Accedi per commentare.

Categorie

Richiesto:

il 13 Mag 2015

Commentato:

il 13 Mag 2015

Community Treasure Hunt

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

Start Hunting!

Translated by