How to ignore Nan value in an iteration
| neogin | February 25, 2010 - 05:44 | ||
|---|---|---|---|
|
Hi guys, I'm a beginner at Igor so don't be offended if my question is trivial : My code is the following : for(o=1;o<10;o=o+1) graph_eq+=(tan(y*sqrt((2*pi*x/lambda)^2-betas[o]^2)-0.5*pi)-sqrt((betas[o]^2-(2*pi/lambda)^2)/((2*pi*x/lambda)^2-betas[o]^2))^2 endfor I've got my x and y scale set, the issue is that for some values of x and betas the part unders the square root is negative, filling the matric graph_eq with Nan values. Do you know a solution to ignore those values or remplace them with 0 ? thanks, |
|||

Joined: 2007-06-29
Location: United States
You can test for NaN with the numtype function.
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
Joined: 2007-06-21
Location: United States
You can change NaNs to 0 like this:
For details on ?:, execute:
You can also use the SelectNumber function instead of ?:
Joined: 2009-11-16
Location: France
Thank you it worked perfectly,
so what I did was to separate each iteration solution, then check for NaN value (& replace with 0 if necessary), and then add the solution to the previous iteration result.
Here's the code if somebody has the same issue :
SetScale/I x 1.4,1.6,"", graph_unit
SetScale/I y 1,3,"micron", graph_unit
for(o=1;o<10;o=o+1)
graph_unit=(tan(y*sqrt((2*pi*x/lambda)^2-betas[o]^2)-0.5*pi)-sqrt((betas[o]^2-(2*pi/lambda)^2)/((2*pi*x/lambda)^2-betas[o]^2)))^2
graph_unit= SelectNumber(numtype(graph_unit)==2, graph_unit, 0)
graph_eq+=graph_unit
endfor
Once again thanks guys.