1 страниц (6 вхождений)
Average If function - Сообщения
#1 Опубликовано: 28.12.2023 03:55:01
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 Опубликовано: 28.12.2023 07:13:05
Martin Kraska
Pre-configured portable distribution of SMath Studio: https://en.smath.info/wiki/SMath%20with%20Plugins.ashx
1 пользователям понравился этот пост
NDTM Amarasekera 28.12.2023 17:38:00
#3 Опубликовано: 28.12.2023 11:58:26
Aha, that should work.
Thanks!
Thanks!
#4 Опубликовано: 28.12.2023 16:04:11
1 пользователям понравился этот пост
NDTM Amarasekera 28.12.2023 17:38:00
#5 Опубликовано: 29.12.2023 05:55:40
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 КиБ) скачан 28 раз(а).
#6 Опубликовано: 29.12.2023 06:19:06
1 пользователям понравился этот пост
NDTM Amarasekera 29.12.2023 09:03:00
1 страниц (6 вхождений)
-
Новые сообщения
-
Нет новых сообщений