Skip to main content
14-Alexandrite
December 23, 2024
Solved

FilterNaN

  • December 23, 2024
  • 1 reply
  • 2244 views

Hi there ,

 

I want to remove NaN from a nested matrix so I can find the average . I tried to use (filterNaN) function but it shows this error 

YA_10963798_0-1734942525056.png

I wrote a program to remove NaN ,, but it does nothing (page 3) in avg sheet

YA_10963798_1-1734942686574.png

my goel is to find the averag without the nans >> because in my original sheet all the average valuse are  shown as NaN 

YA_10963798_2-1734942762277.png

this is on page 22

@StuartBruff 

Stuart >> I'm using the mean function you showed me in this thread:

Solved: Re: average value - PTC Community

Best answer by Werner_E

Here is a more generic function which should be able to deal with nested arrays of any structure and should hopefully also add the appropriate unit. As it works recursively no vectorization should be necessary:

Werner_E_0-1734962002409.png

 

1 reply

25-Diamond I
December 23, 2024

Maybe this alternative mean function could be of help

B.png

 

filterNaN will throw an error if no NaN is found (or if all entries are NaN.

This also applies if you use filterNaN vectorized on a a nested vector.

You may try this alternative function which tried to catch this error - it vas written with vectors (one column matrices) in mind

B2.png

 

According your "YA avg 02.mcdx" file: Is there anywhere in that file the information what exactly you are trying to achieve?? I mean is there anywhere the manually typed in nested vector you want to see as the result of your attempts?

It looks to me like the nested vector n should be the input of your calculations, but its unclear to me, what the output should be.

At first I thought you might be after something like

Werner_E_0-1734954628261.png

 

But then you wrote

Werner_E_1-1734954738890.png

and I had no idea where the value 0.444 would stem from and how it would be derived from the given values ???

 

 

14-Alexandrite
December 23, 2024

it didn't work

YA_10963798_0-1734953500036.png

I tried to write another way

YA_10963798_1-1734953532724.png

it didn't work as well

 

25-Diamond I
December 23, 2024

mean2(), like the original mean() is supposed to work on a vector of scalars, not a nested vector of nested vectors of nested....

The same applies to the deleteNaN function shown above.

Only difference from mean2 and mean is that mean2 properly handles NaNs without throwing an error and that mean2 was written specifically to take one vector argument.

You can use both functions vectorized, though.

But if you use

Werner_E_0-1734955601485.png

you will just get the mean values of the three vectors in n and this seems to be not what you are looking for.

But mean or mean2 will only return the mean value of a vector and not the mean value of a couple of values picked from various vectors in the way you may have in mind - how should Prime know which values you want to play with if you don't collect them in a vector yourself?

I, too am not sure which result with the nested vector n as input you expect to see. See my added remarks above.