Average If function

Average If function - Mensajes

#1 Publicado: 28/12/2023 3:55:01
Fikret Atalay

Fikret Atalay

2 me gusta en 24 mensajes.

Grupo: User

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!
#2 Publicado: 28/12/2023 7:13:05
Martin Kraska

Martin Kraska

1.361 me gusta en 2.275 mensajes.

Grupo: Moderator

Worksheet7.png
Worksheet7.sm (4,2 KiB) descargado 1540 vez(es).

M*c / c*c would also do.
Technische Mechanik mit SMath Studio: https://link.springer.com/book/10.1007/978-3-658-50592-9
A 1 usuarios les gustó este mensaje
NDTM Amarasekera 28/12/2023 17:38:00
#3 Publicado: 28/12/2023 11:58:26
Fikret Atalay

Fikret Atalay

2 me gusta en 24 mensajes.

Grupo: User

Aha, that should work.

Thanks!
#4 Publicado: 28/12/2023 16:04:11
overlord

overlord

600 me gusta en 1.381 mensajes.

Grupo: Moderator

This is another way.

Regards

AverageIf.sm (5,16 KiB) descargado 1573 vez(es).

2023-12-28_11-03.png
A 1 usuarios les gustó este mensaje
NDTM Amarasekera 28/12/2023 17:38:00
#5 Publicado: 29/12/2023 5:55:40
Fikret Atalay

Fikret Atalay

2 me gusta en 24 mensajes.

Grupo: User

Took me a couple of minutes to wrap my head around this one, but now it makes sense.

Thanks!!

Wrote

This is another way.

Regards

AverageIf.sm (5,16 KiB) descargado 1573 vez(es).

2023-12-28_11-03.png



#6 Publicado: 29/12/2023 6:19:06
overlord

overlord

600 me gusta en 1.381 mensajes.

Grupo: Moderator

This maybe an easier way.
Regards

2023-12-29_01-18.png
A 1 usuarios les gustó este mensaje
NDTM Amarasekera 29/12/2023 9:03:00
  • Nuevos mensajes
  • Sin mensajes nuevos