create histogram

I can create histogram of data in range 0 to 180.
but i want to create histogram in range 0 to 89 and 90 to 180.
So my histogram x-axis should be like this

90 ...135...180,0...45.....89

How can i create histogram like that?
Please help me thanks ..
Last edited on
Any one can pls reply me on this topic.
I need to solve it urgently thanks
I think you need to specify your question a little bit. What do you need help with? The coding?
This sounds interesting, Is it related to photography by any chance ?

If you share the code for 0-180, then I'm sure we can figure out how to modify it to do what your asking.
Hy @samuelAdams,

You are right.

This is an example of code for creating histogram./
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>

using namespace std;

int main()
{
   cout << "Hello World" << endl; 
   int arr[100] = {0,10,11,1,2,3,2,3,0,1,2,0,7,10,15,12,11,1,2,1,3
   ,5,6,4,3,2,10,22,0,11,12,1,10,0,11,36,15,26,30,41,11,0,1,0,1,0,1,2,3,4,5,6,4,52
   ,21,5,22,36,12,10,11,25,22,1,2,2,3,4,5,6,1,2,3,4,5,6,11,20,40,50,11,33,25,178,177,178,179,17,178,178,179,156,145,140,14,15,16,17,18,19};
   
   //print array of 100 numbesr
   for(int i = 0; i < 100; i++)
   {
       cout << "@ " << i << " : " << arr[i] << endl;
   }
   
   int histArray[180] = {0};
   
   //assign 0 to all histArray[180]
   for(int i = 0; i < 100; i++)
   {
       histArray[i] = 0;
   }
   
   //calculate histogram array
   for(int i = 0; i < 100; i++)
   {
       histArray[arr[i]]++;
   }
   
   cout << endl;
   cout << "Histogram value at index..." << endl; 
   
   //calculate histogram array in range 0, 180
   for(int i = 0; i < 180; i++)
   {
       cout << i << " : " << histArray[i] << endl;
   }
   
   //but i want to calculate histogram in this range: 90 to 180,0 to 89
   
   
   return 0;
}


How can i create histogram in range 90 to 180,0 to 89.
I don't need histogram in range 0 to 180.

In other sense my histigram should be appeared like this



90 : 0
91 : 0
92 : 0
93 : 0
94 : 0
95 : 0
96 : 0
97 : 0
98 : 0
99 : 0
100 : 0
101 : 0
102 : 0
103 : 0
104 : 0
105 : 0
106 : 0
107 : 0
108 : 0
109 : 0
110 : 0
111 : 0
112 : 0
113 : 0
114 : 0
115 : 0
116 : 0
117 : 0
118 : 0
119 : 0
120 : 0
121 : 0
122 : 0
123 : 0
124 : 0
125 : 0
126 : 0
127 : 0
128 : 0
129 : 0
130 : 0
131 : 0
132 : 0
133 : 0
134 : 0
135 : 0
136 : 0
137 : 0
138 : 0
139 : 0
140 : 1
141 : 0
142 : 0
143 : 0
144 : 0
145 : 1
146 : 0
147 : 0
148 : 0
149 : 0
150 : 0
151 : 0
152 : 0
153 : 0
154 : 0
155 : 0
156 : 1
157 : 0
158 : 0
159 : 0
160 : 0
161 : 0
162 : 0
163 : 0
164 : 0
165 : 0
166 : 0
167 : 0
168 : 0
169 : 0
170 : 0
171 : 0
172 : 0
173 : 0
174 : 0
175 : 0
176 : 0
177 : 1
178 : 4
179 : 2


Pls help me to code up . thansk
Last edited on
Any one ..can help me with that/
what is your histogram all about? how many times a certain numbe appears in arr?
The most trivial thing is to show only the [90..179] range.

Even now you make a dangerous assumption in histArray[arr[i]] -- that the value you use as index is in valid range for histArray. You should test for it. If you do test for it, you can restrict the valid range as you please.z
Last edited on
This isn't what I expected, but I guess it's a work in process.

Try changing lines 33-39 to this, and tell me if that is what your looking for.

1
2
3
4
5
6
7
8
9
10
11
12
   cout << "Histogram value 0-89" << endl; 
   //calculate histogram array in range 0, 180
   for(int i = 0; i < 89; i++)
   {
       cout << i << " : " << histArray[i] << endl;
   }

   cout << "Histogram value 90-180" << endl; 
   for(int i = 90; i < 180; i++)
   {
       cout << i << " : " << histArray[i] << endl;
   }
This is more like what I had in mind, even though it is vertical not horizontal.

1
2
3
4
5
6
7
8
9
10
11
   cout << "Histogram value 90-180" << endl; 
   for(int i = 90; i < 180; i++)
   {
//       cout << i << " : " << histArray[i] ;
       cout << i << " : ";
       for (histArray[i];histArray[i]>=0;histArray[i]--)
       {
    	cout << "X";
       }
       cout << endl;
   }

Last edited on
Yes @SamuelAdams-- Jun 8, 2013 at 3:36am

That is what i want. but originally histogram is saved in range 0 to 180.
You just print the histogram by breaking the range (0 to 180) into 90 to 180 and 0 to 89.
But i want that histogram array itself store the histogram in this range, 0 to 90 to 180 and 0 to 89.

We can make histogram array with a range like
int histogram[180]

that meant this histogram array is from 0 to 180.
but i want that this histogram array should have indexs like 90 to 180, 0 to 89.

Any idea how to do get histogram like that?
Last edited on
In other words, you want an array that has 91 elements, where the first element stores the count of value 90 and the last stores the count for value 180.

Have you considered calculating index from value and vice versa?
No, my array size would be same 180 but .. array range should not be 0 to 180.
I want array range 90 to 180, 0 to 89.
that meant first index of array should be 90 and last index of arry should be 89.
Topic archived. No new replies allowed.