1 Pages (6 items)
Average If function - Messages
#1 Posted: 12/28/2023 3:55:01 AM
Hi all, there seems to be no function similar to the Excel function "AverageIf" in SMath. Let me set up a hypothetical example with two vectors:
z = [1 2 3 4 5]
M = [50 50 25 20 30]
Let's say that I want to calculate the average value of M for z => 3 AND z <=5. In this case, it should be (25+20+30)/3=25. What would be the best way to go about this? The "Mean" function in SMath returns the mean of the whole vector, so when I write a For loop with an If condition to extract values of M for the interval z, I don't know how to assign "blank" values to the cells that fall outside the defined range so it doesn't affect the average if it makes sense. What I then get is (0+0+25+20+30)/5=15
Thanks in advance as always!
z = [1 2 3 4 5]
M = [50 50 25 20 30]
Let's say that I want to calculate the average value of M for z => 3 AND z <=5. In this case, it should be (25+20+30)/3=25. What would be the best way to go about this? The "Mean" function in SMath returns the mean of the whole vector, so when I write a For loop with an If condition to extract values of M for the interval z, I don't know how to assign "blank" values to the cells that fall outside the defined range so it doesn't affect the average if it makes sense. What I then get is (0+0+25+20+30)/5=15
Thanks in advance as always!
#2 Posted: 12/28/2023 7:13:05 AM
Martin Kraska
Pre-configured portable distribution of SMath Studio: https://en.smath.info/wiki/SMath%20with%20Plugins.ashx
1 users liked this post
NDTM Amarasekera 12/28/2023 5:38:00 PM
#3 Posted: 12/28/2023 11:58:26 AM
Aha, that should work.
Thanks!
Thanks!
#5 Posted: 12/29/2023 5:55:40 AM
Took me a couple of minutes to wrap my head around this one, but now it makes sense.
Thanks!!
Thanks!!
WroteThis is another way.
Regards
AverageIf.sm (5 KiB) downloaded 58 time(s).
1 Pages (6 items)
-
New Posts
-
No New Posts