ok so initially we were given a data file with an array of a known size. for me [21][19]. from there we had to determine the median value for each row and column. to do so we had to sort the data from highest to lowest and select the middle column/row which contained the median values. from here we created a median map where numbers 1,0,-1 were assigned to the array.
if the number in a cell was greater then both the median for the row and column a 1 was assigned.
if the number in a cell was less then both the median for the row and column a -1 was assigned.
if neither occured a 0 was assigned.
my output for the median map was perfect.
now for the median map i want to calculate the counts of each row and column respectively.
this code determined the median map, assigning 1,0,-1 respectively.
Code:
/* Create Map */
for (row = 0; row < MAX_ROWS; row++)
{
for (col = 0; col < MAX_COLS; col++)
{
/* if < than both row and col medians */
if (Data[row][col] < RowMedian[row] && Data[row][col] < ColMedian[col])
{
MedianMap[row][col] = MIN_SYM;
}
else
/* if > than both row and col medians */
if (Data[row][col] > RowMedian[row] && Data[row][col] > ColMedian[col])
{
MedianMap[row][col] = MAX_SYM;
}
else
{
MedianMap[row][col] = MIDDLE_SYM;
}
}
}
/* for(row = 0; row < MAX_ROWS; row++)
{
for(col = 0; col < MAX_COLS; col++)
{
printf("%3d ", MedianMap[row][col]);
}
printf("\n");
} */
once the median map is sorted its output looks something like this:
(this is a sample)
1 0 -1 -1 1 1 1 0
0 0 -1 0 -1 1 0 0
-1 -1 0 0 1 1 1 0
Now i want to determine the counts for each column and row. code is as follows
Code:
/* Initialise the variable arrays */
for (row=0; row < MAX_ROWS; row++) ;
{
RowMedian[row] = 0;
RowCounts[row][0] = 0;
RowCounts[row][1] = 0;
RowCounts[row][2] = 0;
}
for (col=0; col < MAX_COLS; col++) ;
{
ColMedian[col] = 0;
ColCounts[col][0] = 0;
ColCounts[col][1] = 0;
ColCounts[col][2] = 0;
}
/* Get Counts */
/* Determine Counts for the rows */
for(row = 0; row < MAX_ROWS; row++)
{
for(col = 0; col < MAX_COLS; col++)
{
if(MedianMap[row][col] == MIN_SYM)
{
RowCounts[row][MIN_SYM_INDEX] = (RowCounts[row][MIN_SYM_INDEX] + 1);
}
else if (MedianMap[row][col] == MAX_SYM)
{
RowCounts[row][1] = (RowCounts[row][1] + 1);
}
else
{
RowCounts[row][2] = (RowCounts[row][2] + 1);
}
}
}
/* determine counts for the cols */
for (col = 0; col < MAX_COLS; col++)
{
for (row = 0; row < MAX_ROWS; row++)
{
if (MedianMap[row][col] == MIN_SYM)
{
ColCounts[col][MIN_SYM_INDEX] = (ColCounts[col][MIN_SYM_INDEX] + 1);
}
else if (MedianMap[row][col] == MAX_SYM)
{
ColCounts[col][MAX_SYM_INDEX] = (ColCounts[col][MAX_SYM_INDEX] + 1);
}
else
{
ColCounts[col][MIDDLE_SYM_INDEX] = (ColCounts[col][MIDDLE_SYM_INDEX] + 1);
}
}
}
Now i want to output the results and show the counts
Code:
printf("RowCounts\n");
for (row = 0; row < MAX_ROWS; row++)
{
printf("%f", RowCounts[col][MIN_SYM_INDEX]);
printf("%f", RowCounts[col][MAX_SYM_INDEX]);
printf("%f", RowCounts[col][MIDDLE_SYM_INDEX]);
}
printf("ColCounts\n");
for (col = 0; col < MAX_COLS; col++)
{
printf("%f", ColCounts[col][MIN_SYM_INDEX]);
printf("%f", ColCounts[col][MAX_SYM_INDEX]);
printf("%f", ColCounts[col][MIDDLE_SYM_INDEX]);
}