I'm converting MatLab code into c.
For MatLab, the code is:
Code:
for (ii = 1:size(A,2))
index = find(A:,ii) > -Inf);
disp(index);
end;
where A is the matrix. The output would give you the row number in each column of the matrix where the value is greater than -Inf.
So far, I have written code that will do all of this except for one thing...store it CORRECTLY as a new matrix. The code I figured out so far is as follows...
Code:
#include<stdio.h>
int main(void)
{
int i, j, size_A=2, size_A2=3;
float A[2][3]= {{-1e300, 2, 3},{2,-1e300,5}}; /*NOTE: -1e300 outputs as -Inf*/
int size_index=0;
int rloc, cloc;
float index[1][size_index];
for(j=0; j<size_A2; j++) /*Finds rows where values in each column are greater than -Inf. Also finds length of new linear matrix*/
{
for(i=0; i<size_A; i++)
{
if(A[i][j]>-1e300)
{
cloc=j+1;
rloc=i+1;
size_index++;
index[1][size_index]= rloc;
printf("col:%d\nrow:%d\nsize:%d\n", cloc, rloc, size_index);
}printf("%d", index[1][size_index]);
}
}
return 0;
}
I used printf to make sure the values of the column, row, and size of the new matrix are all correct. However, the second printf is supposed to print the stored matrix, but my compiler goes haywire. The output should be something like...
2 1 1 2
for this particular matrix.
Thanks.