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.
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:
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:
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.
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:
However, depending on what you want to achieve, maybe this can be done without a loop.
September 27, 2012 at 03:44 am - Permalink
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...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.
September 27, 2012 at 03:59 am - Permalink
that you can do like this (taking wave aa as example):
the "? : " means if any point of aa==0, set it to NaN, otherwise leave as is
September 27, 2012 at 04:06 am - Permalink
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.
September 27, 2012 at 04:15 am - Permalink
Thanks, that's worked perfectly. Being newish to IGOR I tend to end up trying to do everything the long way!
September 27, 2012 at 04:20 am - Permalink