Editing single point in matrix
Jonpope
Hello
Before reading on I am aware this is an extremely basic question, however after consulting the Igor Manual and this forum I've been unable to find an answer to it.
The function below is intended to read through all the data points in a matrix and change any values above 100000 (which indicates a dead pixel in the detector) to zero/NaN.
However I have been unable to find a command that can edit a single point; when doing this manually the command window displayed 'Edit Wavename.Id' which sadly is of no use in a function.
Function Removedeadpixels(thewave)
Wave thewave
variable xx, yy, zz
xx=0
do
yy=0
do
zz= thewave [xx][yy]
if(zz>=100000)
zz=0//Syntax for editing a data point?
endif
yy=yy+1
while (yy<=487)
xx=xx+1
while (xx<=195)
End
Wave thewave
variable xx, yy, zz
xx=0
do
yy=0
do
zz= thewave [xx][yy]
if(zz>=100000)
zz=0//Syntax for editing a data point?
endif
yy=yy+1
while (yy<=487)
xx=xx+1
while (xx<=195)
End
Also in it's current form would the function save the changes in the wave if it is in a string when used in other functions?
Thanks in advance
Jon
thewave = thewave >= 100000 ? nan : thewave
. This changes all datapoints tonan
in thewave if they are equal or greater than 100000.A
March 1, 2012 at 02:50 am - Permalink
executing
DisplayHelpTopic "Multidimensional Wave Assignment"
in the command line will open the relevant help section.
For your application you can also have a look at FindLevels which is faster than homebrewn code.
March 1, 2012 at 02:50 am - Permalink
In your example, you define zz which takes a value from theWave, but then in your if-statement you actually change zz, but not the point in the wave. You would need:
if (theWave[xx][yy] >= 100000)
theWave[xx][yy] = 0
endif
But as already pointed out, your task can be done with a one-liner.
March 1, 2012 at 03:03 am - Permalink
March 1, 2012 at 04:12 am - Permalink
Sorry to butt in on this thread but I have seen this kind of syntax on the forum before and it seems like a nice way of doing in one line what an
if
loop would do. Are there any sections in the manual which describe this notation?Thanks
Tom
March 1, 2012 at 04:33 am - Permalink
March 1, 2012 at 04:59 am - Permalink
Here is one more way to accomplish the task that is probably a bit more efficient:
If you want to set something above threshold to NaN:
MatrixOP/O processedWave=theWave*(greater(threshold,theWave)/greater(threshold,theWave))
If you want to replace the NaNs with any particular value:
I hope this helps,
A.G.
WaveMetrics, Inc.
March 1, 2012 at 10:00 am - Permalink
May 16, 2012 at 04:22 am - Permalink