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

Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X

Working with filters on vectors

ptc-4733643
3-Visitor

Working with filters on vectors

Hi all, I am putting together a calculation sheet where the input data is entered using the Excel component. The first column is the thickness of my layers, called h. In the "Outputs" section of the Excel component, I define h as having a range between cell A2 and A21 (so maximum number of layers is 20). However, if the user enters less than 20 layers, I wanted to give the option to not have to change the range definition so I was using a filter function to remove all non-defined values of h as follows:

 

h := filterNaN(markNaN(h,match(0,h)))

 

This works great; for example, if I define 9 layers, I get a vector length of 9, even though up to 20 layers can be entered.

 

However, one of the other input variables, called OCR, applies to some layers and doesn't apply to others. For the layers that it doesn't apply to, I enter "NaN" in the cell to show that it is not applicable as below:

 

h (m)OCR
0.52
0.52
0.52
0.52
0.5NaN
0.5NaN
0.5NaN
0.5NaN
0.5NaN

 

However, if I use a similar filter function, replacing the "0" with "NaN", of course it cuts of the length of the OCR vector to 4. I tried writing a for loop instead but some reason that is still giving me a vector length of 20. 

 

Any thoughts? Thanks in advance!

 

 

2 REPLIES 2

Ignore this question; apparently all I needed was to step away from the computer for a couple of minutes and stretch my legs a little bit to get my brain kick-started to function properly again 🙂 Got it all figured out.


@ptc-4733643 wrote:

Ignore this question; apparently all I needed was to step away from the computer for a couple of minutes and stretch my legs a little bit to get my brain kick-started to function properly again 🙂 Got it all figured out.


That happens quite often - a little break can sometimes do wonders 😉

Guess you simply trim the second vector down to the size of the first one using the submatrix() function.

 

BTW, you may also use h:=trim(h, match(0,h)) to delete the rows which contain a zero.

Top Tags