tags:

views:

36

answers:

1

Now I get a 5-d matrix which M[j][i][l][ref][0]...

In this matrix, j,i belong to 0~4, while l=0. ref can vary from 0 to 4.

I just want to count the number according to ref's value.

For example,

  • if ref =0, I will do count0++,
  • if ref =1, count1++,
  • if ref =2, count2++
  • ...

So, I do not care what is the value of M, I just want to know the appearing frequency with different ref value.

Thanks.

+2  A: 

You're not quite clear on how what you want to do depends on the actual contents of M -- I'm guessing this contains some sort of variable count you want to add to your individual counts?

In this case, how about something like this:

int j, i, ref;
int counts[5];
for(ref=0; ref<5; ref++)
    counts[ref]=0;
for(j=0; j<4; j++)
    for(i=0; i<5; i++)
        for(ref=0; ref<5; ref++)
            counts[ref]+=M[j][i][0][ref][0];

(I have replaced your individual "count" variables with an array, which makes things much easier.)

Edit: I just saw that you don't care what the contents of M are. In that case, I don't really understand what you're trying to do. Since the dimensions are constant, the number of entries that exist for a certain value of ref are always constant, and are always the same for all ref -- in this case, 5*5=25, since you have five entries along each of the j and i dimensions.

If this is not what you want, please clarify.

Martin B
thank you first..actually, M[][][][][][]'s value is independent with counting operation. In your last step, you use counts[ref]+=M[j][i][l][ref][0]; its kind of like sum operation, right? I only want to know the appearing numbers when ref=0? ref=1? ref=2?....
MaiTiano
I'm still not clear on what you want to do -- see edit above.
Martin B