cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X

FILTERING NaN

ppal
17-Peridot

FILTERING NaN

Hi All

Help required as below. Thanks and Happy New Year.

 

ppal_0-1641352032378.png

 

ACCEPTED SOLUTION

Accepted Solutions
Werner_E
25-Diamond I
(To:ppal)

> They will not occur in beween valid numbers. 

Where the Nan's are in a column does not matter at all. The buitl-in function "filterNaN" throws an error on two situations:

1) no NaN in the matrix (thats silly as it just should return the original matrix unchanged) this is fixed by my first attempt above

2) NaN is in every row of the matrix. Here we would expect an empty matrix but thats something not provided by Prime. My last two attempts try to fix this by returning NaN instead of a matrix.

 

in your case you could write a program with a loop that counts and stops when the first value in a column is not a scalar. But as along as the column contains at least one scalar, my short first rewrite of "filterNan" should do the job.

 

View solution in original post

8 REPLIES 8
Werner_E
25-Diamond I
(To:ppal)

Simply write your own, modified "filterNaN" using try and catch

Werner_E_0-1641354913140.png

Note, that you may still run into problems if the argument contains a NaN in every row. You will get back the argument unmodified. Thats no along the logic of the function as you should get back kind of an empty matrix (which unfortunately does not exist in Prime).

 

In your pic you write that you expect 0 as a result. I guess you'd rather expect a return value of 19!

 

BTW, I guess you were already told in other threads, ALWAYS include your worksheet if ever possible! If the sheet contains sensible data you are not allowed to share, create a demo worksheet without that data but still showing the problem.

 

Werner_E
25-Diamond I
(To:Werner_E)

Here is a routine which returns NaN in case all rows contain a NaN.

At least rows(NaN) returns 0 so it will work OK in the context of your example:

Werner_E_0-1641356647543.png

 

Werner_E
25-Diamond I
(To:Werner_E)

Guess its easier that way:

Werner_E_0-1641357036115.png

 

ppal
17-Peridot
(To:Werner_E)

Hi

 

Thanks for that. The data will only have NaN  after the end of valid numerical values. They will not occur in beween valid numbers. I have attached a sample dta file and a mathcad Prime 7 file. Hope that makes it bit clearer. The really small numbers are effectively zero.Thank you.

Werner_E
25-Diamond I
(To:ppal)

> They will not occur in beween valid numbers. 

Where the Nan's are in a column does not matter at all. The buitl-in function "filterNaN" throws an error on two situations:

1) no NaN in the matrix (thats silly as it just should return the original matrix unchanged) this is fixed by my first attempt above

2) NaN is in every row of the matrix. Here we would expect an empty matrix but thats something not provided by Prime. My last two attempts try to fix this by returning NaN instead of a matrix.

 

in your case you could write a program with a loop that counts and stops when the first value in a column is not a scalar. But as along as the column contains at least one scalar, my short first rewrite of "filterNan" should do the job.

 

StuartBruff
23-Emerald III
(To:ppal)


@ppal wrote:

Hi

 

Thanks for that. The data will only have NaN  after the end of valid numerical values. They will not occur in beween valid numbers. I have attached a sample dta file and a mathcad Prime 7 file. Hope that makes it bit clearer. The really small numbers are effectively zero.Thank you.


Here's a version of filterNaN for those of you with only Mathcad Express.

 

2022 01 05 a.png

 

Application of filterNaN to DATA from CSV file:

 

2022 01 05 c.png

 

Here are the other functions used in the making of the filterNaN reboot. 

 

2022 01 05 b.png

 

Note that the new function will only process about 4,500 rows before running into Mathcad's recursion depth limit, but it should be simple enough to break a larger array into pieces, process them and join up the filtered pieces.

 

Stuart

Werner_E
25-Diamond I
(To:StuartBruff)

Guess your "not_element_of" function has a problem with NaN's.

Why not simply
Werner_E_0-1641426877192.png

 

StuartBruff
23-Emerald III
(To:Werner_E)


@Werner_E wrote:

Guess your "not_element_of" function has a problem with NaN's.


I must have accidentally hit the delete button at some point.  There should be "=" between the max expression and the zero.

 


@Werner_E wrote:

Why not simply
Werner_E_0-1641426877192.png


Because I was being lazy and copied/simplified it from another worksheet where the ordering of a further (omitted) expression did make a difference.   

 

Also, I sometimes like to save unnecessary function calls(*) and to have an independent implementation to act as a crosscheck.

 

Stuart

 

(*) A hangover from my early computing days where every clock cycle and byte counted!  It's still sometimes helpful when dealing with complex calculations on large data sets. 

Announcements

Top Tags