Hey guys, I have an array or [21]rows and [19]cols. Each row and column have the numbers -1,0,1 scattered randomly throughout the array from what was a medianmap. Now i want to calculate the counts for each respective column and row for 1,0,-1. I have written the code although it wont output correctly, below is the code followed by the print statement.
your help would be appreciated.
Code:
/* Declare any constants */
/* Input file name */
#define FILE_NAME "data-5.csv"
/* Data size */
#define MAX_COLS 19
#define MAX_ROWS 21
/* Map symbols */
#define MIN_SYM -1
#define MAX_SYM 1
#define MIDDLE_SYM 0
/* Use to reference the counts */
#define MIN_SYM_INDEX 0
#define MAX_SYM_INDEX 1
#define MIDDLE_SYM_INDEX 2
#define MAX_COUNTS 3
/* Declare any variables */
/* Used to hold the index of the row/col that is the middle value */
int MedianIndex1 = 0;
/* Used to hold the index of the row/col when there is an even number of rows/cols */
int MedianIndex2 = 0;
/* 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;
}
Code:
/* 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);
}
}
}
print statement.
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]);
}