Rank: Member Groups: Registered
Joined: 21/11/2023(UTC) Posts: 24 Was thanked: 2 time(s) in 2 post(s)
|
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! Edited by user 28 December 2023 09:56:39(UTC)
| Reason: Not specified
|
|
|
|
Rank: Advanced Member Groups: Registered
Joined: 15/04/2012(UTC) Posts: 1,988 Was thanked: 1127 time(s) in 723 post(s)
|
|
|
1 user thanked mkraska for this useful post.
|
|
|
Rank: Member Groups: Registered
Joined: 21/11/2023(UTC) Posts: 24 Was thanked: 2 time(s) in 2 post(s)
|
Aha, that should work.
Thanks!
|
|
|
|
Rank: Advanced Member Groups: Registered
Joined: 23/07/2013(UTC) Posts: 1,129 Was thanked: 510 time(s) in 340 post(s)
|
This is another way. Regards AverageIf.sm (6kb) downloaded 3 time(s).
|
1 user thanked overlord for this useful post.
|
|
|
Rank: Member Groups: Registered
Joined: 21/11/2023(UTC) Posts: 24 Was thanked: 2 time(s) in 2 post(s)
|
Took me a couple of minutes to wrap my head around this one, but now it makes sense. Thanks!! Originally Posted by: overlord This is another way. Regards AverageIf.sm (6kb) downloaded 3 time(s).
|
|
|
|
Rank: Advanced Member Groups: Registered
Joined: 23/07/2013(UTC) Posts: 1,129 Was thanked: 510 time(s) in 340 post(s)
|
This maybe an easier way. Regards
|
1 user thanked overlord for this useful post.
|
|
|
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.