Skip to main content
1-Visitor
July 23, 2019
Question

Matrix and NAN filtering

  • July 23, 2019
  • 2 replies
  • 4732 views

Good day everyone,

 

I have a matrix with test results from different kinds of tests (500 x 1000 in size). 

In the first 5 columns it tells which tests are done by either a true statement or nothing. 

For calculation I want to select specific parameters from specific columns that are only done for a specific test.

 

To do that I think I need to filter make a new matrix where I only select all rows where a test is true. After that I can select the right colums for the parameters.

 

I am afraid I cannot share my original file but I made a small example of what I am trying to achieve

In the first matrix the first 3 columns represent the output if a certain test has been done. columns 4 to 6 represent the test outcomes I want to use for my calcylations. The 3 matrixes below are the desired output.

I hope someone can help me with this. 

 

2 replies

23-Emerald IV
July 23, 2019

I remember that the FilterNan() function isn't always as reliable as you'd expect, but that may be limited to Mathcad 15...

 

If you replace the NaN's with zero's (0) and the True's with negative one's (-1), you can use the csort() function and select column 0, 1 or 2, then use match() to find the last -1 in that column, which gives you the row index of where it's 'true'. With the total number of rows and columns in the matrix, AND that row index you can call the submatrix() function to get the exact part of the matrix that you need.

 

The attached should help...

 

Success!

Luc

GvanBoven1-VisitorAuthor
1-Visitor
July 23, 2019

Hello Luc,

 

Thanks for your response

 

I have read some things about the FilterNAN not working proberly before Mathcad 3,0 on this forum. I am however using 3.1. That brings me to my next question about the document you uploaded. Can you save it for mathcad 3.1 so I can open it.

 

I also need to add here that in the real file not all data fields are filled either. That was a mistake on my part making the example. In the real sheet I also have tests that do not give every paramater. They also show up after import as NaN

 

 

23-Emerald IV
July 23, 2019

Hier is 'tie:

 

Veel plezier!
Luc

25-Diamond I
July 23, 2019

This should do the job.

Don't have P31 installed an PTC software is silly enough not to be able in older formats, so all you get is a picture:

B.png

 

While "Match" or the various "Lookup" functions often provide reason for complaint, I am not aware that "filterNaN" would do so, too. But filterNaN would not be very useful for your problem, as it would remove every row in your matrix which contains one or more NaN's, which in your case would mean it will remove every row leaving nothing which again would result in an error.

You may user "filterNaN" if you want to omit the test columns not in question from your output, though:

B2.png