Do someone know how to plot the histogram by uisng the simple C++ codes?
Actually i dont have any idea to start it..so hope that you all can help to solve it...
thanks..
How to plot Histogram by using C++?
Page 1 of 13 Replies - 78917 Views - Last Post: 11 March 2007 - 02:14 PM
Replies To: How to plot Histogram by using C++?
#2
Re: How to plot Histogram by using C++?
Posted 11 March 2007 - 08:26 AM
Well you don't give us much to go on here. Histogram of what? What kind of plot are you looking for?
if I wanted a histogram of pixel colors in a 256 color bitmap I would create an array of 256 integers, then loop though the bitmap and add 1 to the value in my integer array which corresponded to the current color. THEN, I would find the maximum and minimum values in the array, normalize it, and then plot it onto a bitmap...
Basicly you don't give us enough to go on here. What are you trying to do? what have you tried so far?
if I wanted a histogram of pixel colors in a 256 color bitmap I would create an array of 256 integers, then loop though the bitmap and add 1 to the value in my integer array which corresponded to the current color. THEN, I would find the maximum and minimum values in the array, normalize it, and then plot it onto a bitmap...
Basicly you don't give us enough to go on here. What are you trying to do? what have you tried so far?
#3
Re: How to plot Histogram by using C++?
Posted 11 March 2007 - 09:23 AM
Erm...actually i really dont know how i gonna to start it..
Let said i have a set of data (in attachment) then i would like to plot the histogram (eg. in attachment) by using C++..
Then the output will show the histogram... just a simple histogram..no need involve any graphic function..just print it in the "black box" only...
Let said i have a set of data (in attachment) then i would like to plot the histogram (eg. in attachment) by using C++..
Then the output will show the histogram... just a simple histogram..no need involve any graphic function..just print it in the "black box" only...
Attached File(s)
-
Histogram.doc (35K)
Number of downloads: 3289
#7
Re: How to plot Histogram by using C++?
Posted 11 March 2007 - 02:14 PM
Well lets say we will use text graphics so our histogram looks like this:
00-09: *
10-19: **
20-29: ***
30-39: ****
40-49: *****
50-59: ****
60-69: ***
70-79: **
80-89: *
90-99: *
We will need to create an array of 10 integers (our bins).
Next loop though the data and sorting it into our bins:
Then we can make a little output function to display the histogram:
This is of course only one way to do it...
00-09: *
10-19: **
20-29: ***
30-39: ****
40-49: *****
50-59: ****
60-69: ***
70-79: **
80-89: *
90-99: *
We will need to create an array of 10 integers (our bins).
Next loop though the data and sorting it into our bins:
if (data =>0 && data <10) {bin[0]++; }
else if (data =>10 && data <20) {bin[1]++; }
else if (data =>20 && data <30) {bin[2]++; }
.
.
.
// or put it into a loop:
for (i=0; i<10;i++)
{ if ((data[j] >= 10*i) && (data[j] < 10*i+9)) {bin[i]++; } }
Then we can make a little output function to display the histogram:
cout << "00-09: ";
for (i=0;i<bin[j];i++) {cout << "*"; }
This is of course only one way to do it...
Page 1 of 1

New Topic/Question
Reply




MultiQuote



|