tiscavalcanti Posted January 8, 2016 Share Posted January 8, 2016 (edited) I want to get the value that is in the center between three values. For example: Math."middle"(34.78, 56.12, 45.54) Result in: 45.54 How I can do this? Edited January 8, 2016 by tiscavalcanti Link to comment Share on other sites More sharing options...
davej Posted January 8, 2016 Share Posted January 8, 2016 Three given values? Why not use an exhaustive if-then-else construct? Your question is oddly worded because you might also be implying the arithmetic average which is 45.45. Link to comment Share on other sites More sharing options...
justsomeguy Posted January 8, 2016 Share Posted January 8, 2016 You can either write your own function to return the median of an array, or you can use a library that includes one. http://mathjs.org/docs/reference/functions/median.html 1 Link to comment Share on other sites More sharing options...
tiscavalcanti Posted January 8, 2016 Author Share Posted January 8, 2016 (edited) You can either write your own function to return the median of an array, or you can use a library that includes one. http://mathjs.org/docs/reference/functions/median.html Thanks, but I believe which Math.median() don't work in After Effects Software by expression. I get a error ("Math.median is not a function"). Three given values? Why not use an exhaustive if-then-else construct? Your question is oddly worded because you might also be implying the arithmetic average which is 45.45. I could use if/else but, in my case, the values are not fixed, this value that I show is just example. How i can do this between if/else? Edited January 8, 2016 by tiscavalcanti Link to comment Share on other sites More sharing options...
davej Posted January 8, 2016 Share Posted January 8, 2016 Again, your question is oddly worded. Are you saying that you want to supply three values to a function and receive the "middle" value back? function middle(a,b,c){ if ((a > b && a < c)||(a > c && a < ){ return a; }else if ((b > a && b < c)||(b > c && b < a)){ return b; }else if ((c > a && c < ||(c > b && c < a)){ return c; }else{ return -999; // if a = b or a = c or b = c } }//end of function 1 Link to comment Share on other sites More sharing options...
tiscavalcanti Posted January 8, 2016 Author Share Posted January 8, 2016 Again, your question is oddly worded. Are you saying that you want to supply three values to a function and receive the "middle" value back? I want the value of a property of my program, to which this code is entered, is defined by the value of another property that is between two other properties, ie three properties, I do not even want Math.max or Math. min, but the value is between these two. Link to comment Share on other sites More sharing options...
justsomeguy Posted January 8, 2016 Share Posted January 8, 2016 Thanks, but I believe which Math.median() don't work in After Effects Software by expression. I get a error ("Math.median is not a function").The website I linked to hosts the library which defines it. It is not built in to Javascript. They wrote their own function to do it, and you can download their library to define that method and whatever else the library includes. Or, like I said, write your own. 1 Link to comment Share on other sites More sharing options...
justsomeguy Posted January 8, 2016 Share Posted January 8, 2016 And the term you're looking for is the statistical median. It's already a defined term. It's not the "middle", it's the median value. https://en.wikipedia.org/wiki/Median 1 Link to comment Share on other sites More sharing options...
davej Posted January 8, 2016 Share Posted January 8, 2016 I want the value of a property of my program, to which this code is entered, is defined by the value of another property that is between two other properties, ie three properties, I do not even want Math.max or Math. min, but the value is between these two. This would be much simpler if you actually provided an example of what you want this function to do. You seemed to do this in your first post above, but now I'm not sure. Link to comment Share on other sites More sharing options...
tiscavalcanti Posted January 8, 2016 Author Share Posted January 8, 2016 Again, your question is oddly worded. Are you saying that you want to supply three values to a function and receive the "middle" value back? function middle(a,b,c){ if ((a > b && a < c)||(a > c && a < ){ return a; }else if ((b > a && b < c)||(b > c && b < a)){ return b; }else if ((c > a && c < ||(c > b && c < a)){ return c; }else{ return -999; // if a = b or a = c or b = c } }//end of function Thanks for your time, my friend. This forum like ever, very efficient. Work very well. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now