Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X
> 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.
Simply write your own, modified "filterNaN" using try and catch
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.
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:
Guess its easier that way:
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.
> 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.
@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.
Application of filterNaN to DATA from CSV file:
Here are the other functions used in the making of the filterNaN reboot.
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
Guess your "not_element_of" function has a problem with NaN's.
Why not simply
@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
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.