For Loop on a multidimensional wave

I've got a wave with approximately 30 columns and 1000 rows that I want to act on. I'm used to using 'numpnts' but in the help it refers me to dimsize to define number of data points. However it's still not clear which dimnumber to use in the for loop. I'm not sure what 'Layers' or 'Chunks' refers to and both 'rows' and 'columns' don't seem to do the job.

Any ideas?

It is not clear what you want to do and what "doesn't do the job" mean. Do you want to loop through every single point of the matrix in a nested for-loop? In that case layers and chunks are irrelevant because they represent the third and fourth array dimension which you don't have. "numpnts" is equivalent to e.g. DimSize(w,0), e.g. 0 refers to the number of rows, 1 to the number columns in wave w. If you want to access every single point in a matrix you can use something like this:

make/o/n=(4,3) aa=p+4*q; edit aa


function test(w)
    wave w
   
    variable ii, jj
   
    for (ii=0; ii<dimsize(w, 1); ii+=1)
        for(jj=0; jj<dimsize(w, 0); jj+=1)
       
            print w[jj][ii]
           
        endfor
    endfor     
   
end


and run it by executing:

test(aa)



However, depending on what you want to achieve, maybe this can be done without a loop.

ChrLie wrote:
It is not clear what you want to do and what "doesn't do the job" mean. Do you want to loop through every single point of the matrix in a nested for-loop? In that case layers and chunks are irrelevant because they represent the third and fourth array dimension which you don't have. "numpnts" is equivalent to e.g. DimSize(w,0), e.g. 0 refers to the number of rows, 1 to the number columns in wave w. If you want to access every single point in a matrix you can use something like this:

make/o/n=(4,3) aa=p+4*q; edit aa


function test(w)
    wave w
   
    variable ii, jj
   
    for (ii=0; ii<dimsize(w, 1); ii+=1)
        for(jj=0; jj<dimsize(w, 0); jj+=1)
       
            print w[jj][ii]
           
        endfor
    endfor     
   
end


and run it by executing:

test(aa)



However, depending on what you want to achieve, maybe this can be done without a loop.


By not doing the job I mean that specifying dimnumber 0 or 1 edits either the entire first column (in the case of 0) or just the first 30 rows of the first column (in the case of 0). What I'm trying to do is go to every single data point and nan any zeros. I've just tried this below, which works on the first 30 rows of every column...

function data()
variable ii, jj
wave data
    for (ii=0;ii<=dimsize(data,1);ii+=1)
        for (jj=0;jj<=dimsize(data,0);jj+=1)
            if (data[ii][jj]==0)
               data[ii][jj]=nan
            endif
        endfor
    endfor
end    


I think what I need to do is use a nested for-loop, which I've tried above but it doesn't work on the whole matrix.

Thanks.
thunderstruck wrote:
What I'm trying to do is go to every single data point and nan any zeros.
Thanks.


that you can do like this (taking wave aa as example):

aa = aa==0 ? NaN : aa


the "? : " means if any point of aa==0, set it to NaN, otherwise leave as is
thunderstruck wrote:

I think what I need to do is use a nested for-loop, which I've tried above but it doesn't work on the whole matrix.


I think your indexing is wrong, try:

if (data[jj][ii]==0)
data[jj][ii]=nan

with ii you should be running though columns, but you're going through rows.
ChrLie wrote:
thunderstruck wrote:
What I'm trying to do is go to every single data point and nan any zeros.
Thanks.


that you can do like this (taking wave aa as example):

aa = aa==0 ? NaN : aa


the "? : " means if any point of aa==0, set it to NaN, otherwise leave as is


Thanks, that's worked perfectly. Being newish to IGOR I tend to end up trying to do everything the long way!