Welcome Guest! To enable all features please Login. New Registrations are disabled.

Notification

Icon
Error

Login


Options
Go to last post Go to first unread
Offline gth802s  
#1 Posted : 28 December 2023 09:55:01(UTC)
gth802s


Rank: Member

Groups: Registered
Joined: 21/11/2023(UTC)
Posts: 24
United States

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

Wanna join the discussion?! Login to your SMath Studio Forum forum account. New Registrations are disabled.

Offline mkraska  
#2 Posted : 28 December 2023 13:13:05(UTC)
mkraska


Rank: Advanced Member

Groups: Registered
Joined: 15/04/2012(UTC)
Posts: 1,986
Germany

Was thanked: 1124 time(s) in 721 post(s)
Worksheet7.png
Worksheet7.sm (5kb) downloaded 3 time(s).

M*c / c*c would also do.

Edited by user 28 December 2023 13:15:32(UTC)  | Reason: Not specified

Martin Kraska

Pre-configured portable distribution of SMath Studio: https://smath.com/wiki/SMath_with_Plugins.ashx
thanks 1 user thanked mkraska for this useful post.
on 28/12/2023(UTC)
Offline gth802s  
#3 Posted : 28 December 2023 17:58:26(UTC)
gth802s


Rank: Member

Groups: Registered
Joined: 21/11/2023(UTC)
Posts: 24
United States

Was thanked: 2 time(s) in 2 post(s)
Aha, that should work.

Thanks!
Offline overlord  
#4 Posted : 28 December 2023 22:04:11(UTC)
overlord


Rank: Advanced Member

Groups: Registered
Joined: 23/07/2013(UTC)
Posts: 1,128
Turkey

Was thanked: 509 time(s) in 339 post(s)
This is another way.

Regards

AverageIf.sm (6kb) downloaded 3 time(s).

2023-12-28_11-03.png
thanks 1 user thanked overlord for this useful post.
on 28/12/2023(UTC)
Offline gth802s  
#5 Posted : 29 December 2023 11:55:40(UTC)
gth802s


Rank: Member

Groups: Registered
Joined: 21/11/2023(UTC)
Posts: 24
United States

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 Go to Quoted Post
This is another way.

Regards

AverageIf.sm (6kb) downloaded 3 time(s).

2023-12-28_11-03.png


Offline overlord  
#6 Posted : 29 December 2023 12:19:06(UTC)
overlord


Rank: Advanced Member

Groups: Registered
Joined: 23/07/2013(UTC)
Posts: 1,128
Turkey

Was thanked: 509 time(s) in 339 post(s)
This maybe an easier way.
Regards

2023-12-29_01-18.png
thanks 1 user thanked overlord for this useful post.
on 29/12/2023(UTC)
Users browsing this topic
Guest
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.