Replacing NaN elements in a wave with a number

tomy77
Posts: 5
Joined: 2017-04-30
Location: Japan

I have a 3D wave, waveA, where some of its elements are NaN. How can I replace all of these NaN elements with a numerical value, e.g. 100.0, without using loop?


hegedus
Posts: 327
Joined: 2009-03-21
Location: United States

Hi,

Matrixop destwave=replaceNaNs(your3Dwave,100)

Andy


_sk
Posts: 115
Joined: 2014-10-28
Location: Switzerland

I don't know what matrixop does behind the scenes but I suspect it is something like this, in other words, a hidden loop:

variable v_val = 99
waveA = (numtype(waveA[p]) == 2) ? v_val : waveA[p]

where v_val is the value you want to change the NaNs to (i.e. 99 in this case).

I don't know how the snippet is optimized internally by the igor pro interpreter, so it may be slower than using matrixop. But the snippet above allows you to build other logical functions/ filters for wave elements.

best,
_sk


tomy77
Posts: 5
Joined: 2017-04-30
Location: Japan

Thanks for you both, it seems like matrixop is faster but it's also good to have other form of codes which does the same and can be generalized to another wave filtering operation.


_sk
Posts: 115
Joined: 2014-10-28
Location: Switzerland

It goes without saying that in 3D one would have to traverse over all dimensions, i.e.:
waveA = (numtype(waveA[p][q][r]) == 2) ? 99 : waveA

best,
_sk


thomas_braun
Posts: 586
Joined: 2009-10-07
Location: Germany

Don't forget to use MultiThread on wave assignments with large waves.


wings
Posts: 65
Joined: 2016-04-27
Location: China

_sk wrote:
I don't know what matrixop does behind the scenes but I suspect it is something like this, in other words, a hidden loop:

variable v_val = 99
waveA = (numtype(waveA[p]) == 2) ? v_val : waveA[p]

where v_val is the value you want to change the NaNs to (i.e. 99 in this case).

I don't know how the snippet is optimized internally by the igor pro interpreter, so it may be slower than using matrixop. But the snippet above allows you to build other logical functions/ filters for wave elements.

best,
_sk

Great!!
with mutithread key word,that is why Igor so powerfull!


tomy77
Posts: 5
Joined: 2017-04-30
Location: Japan

Hey,
sorry for leaving this thread for one day without updating. So I what I want is actually to use interpolate3D to get the 3D wave and for points lying outside the domain of the source wave this command will return NaN. That's why in the end my 3D wave will contain some NaN elements. However, yesterday I noticed that with my source wave for triangulate3D (I need the output from this command to run the subsequent interpolate3D) being very large (2050401 rows and 4 cols), the execution time exceeded 24 hours until I aborted it before finish. I see someone mentioning MultiThread, looks like some parallel computation related term. Will it help speeding up triangulate3D?


[ last edited July 11, 2017 - 17:45 ]
wings
Posts: 65
Joined: 2016-04-27
Location: China

tomy77 wrote:
Hey,
sorry for leaving this thread for one day without updating. So I what I want is actually to use interpolate3D to get the 3D wave and for points lying outside the domain of the source wave this command will return NaN. That's why in the end my 3D wave will contain some NaN elements. However, yesterday I noticed that with my source wave for triangulate3D (I need the output from this command to run the subsequent interpolate3D) being very large (2050401 rows and 4 cols), the execution time exceeded 24 hours until I aborted it before finish. I see someone mentioning MultiThread, looks like some parallel computation related term. Will it help speeding up triangulate3D?

It is not practical to use triangulate3D operation for very large data sets.

In your case, I think you should think of other ways to do your work. Say, pay attention to the speciality of your data and find a spcial method just suited to your need!


[ last edited July 11, 2017 - 18:22 ]
Igor's picture
Posts: 810
Joined: 2007-06-29
Location: United States

The triangulation process is O(N^2) so you are really looking at a very long computation. Depending on your application you might consider reducing the amount of data that is being triangulated, grouping parts of the data, triangulating and interpolating in smaller groups and similar approaches where you simply reduce the size of N.


Back to top