Pick a number from a list if condition is meet

Pick a number from a list if condition is meet - Messages

#1 Posted: 3/12/2024 3:31:22 PM
Alex Costila

Alex Costila

1 likes in 13 posts.

Group: User

How can i pick a speed based on a "n" value.


Let's say my n= 13 i want to get the value 30km/h for V, but if its 8 i want 60km/h.
I have tried with for/while/if. But im guessing im doing something wrong or i don't know what to write exactly.


Any help is much apprecite it!
#2 Posted: 3/12/2024 5:18:17 PM
Martin Kraska

Martin Kraska

1222 likes in 2150 posts.

Group: Moderator

Worksheet6.png
Worksheet6.sm (4 KiB) downloaded 25 time(s).
Martin Kraska Pre-configured portable distribution of SMath Studio: https://en.smath.info/wiki/SMath%20with%20Plugins.ashx
#3 Posted: 3/12/2024 5:41:24 PM
Alex Costila

Alex Costila

1 likes in 13 posts.

Group: User

Wrote

Worksheet6.png
Worksheet6.sm (4 KiB) downloaded 25 time(s).



Thank you for the answer, but this doesn't help me. Or i don't understand it .

Example, i have N=10, based on N i want to get V. V for N=10 it's from here:
, but if i change N to 9 i want to obtain V=30km/hr.
Thing is i have 8 variable based on N, and i want to obtain the values only by changing N.


Sorry if i don't explain very well.
#4 Posted: 3/12/2024 6:28:42 PM
Martin Kraska

Martin Kraska

1222 likes in 2150 posts.

Group: Moderator

The procedure is to get a vector of the potential values which can then be accessed by index.
You also could implement it as a function v(n) = 30 + mod(n-1, 4)*10

Worksheet6a.png
Martin Kraska Pre-configured portable distribution of SMath Studio: https://en.smath.info/wiki/SMath%20with%20Plugins.ashx
#5 Posted: 3/12/2024 6:51:40 PM
Alex Costila

Alex Costila

1 likes in 13 posts.

Group: User

Wrote

The procedure is to get a vector of the potential values which can then be accessed by index.
You also could implement it as a function v(n) = 30 + mod(n-1, 4)*10

Worksheet6a.png



Great it works now. I just have to figure it out how to implement it for the rest of the file .
Thank you very much!

How would you tackle this one?
#6 Posted: 3/12/2024 8:52:27 PM
Martin Kraska

Martin Kraska

1222 likes in 2150 posts.

Group: Moderator

Wrote



Great it works now. I just have to figure it out how to implement it for the rest of the file .
Thank you very much!

How would you tackle this one?



Divide n by 2, a bit of rounding and offset adjustment should do the job.

Martin Kraska Pre-configured portable distribution of SMath Studio: https://en.smath.info/wiki/SMath%20with%20Plugins.ashx
#7 Posted: 3/18/2024 8:26:30 PM
Alex Costila

Alex Costila

1 likes in 13 posts.

Group: User

Wrote

Wrote



Great it works now. I just have to figure it out how to implement it for the rest of the file .
Thank you very much!

How would you tackle this one?



Divide n by 2, a bit of rounding and offset adjustment should do the job.



I can't seem to get it to work, and for next examples i need to match it with a list that has some randomnes in number list. Isn't there a way i can create a list of number and if my "n" matches that list then i can get the correct value? I tried with for, if and so on. but im still a newbie in Smath.

Thank you once again!
#8 Posted: 3/18/2024 9:19:04 PM
Davide Carpi

Davide Carpi

1415 likes in 2872 posts.

Group: Moderator

If you have a limited set of choiches, this might be a solution.

Screenshot 2024-03-18 141755.png

Also, I think Martin has a point, since these "n" values should come from some formula.
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
#9 Posted: 3/19/2024 2:10:00 AM
Martin Kraska

Martin Kraska

1222 likes in 2150 posts.

Group: Moderator

Wrote

Wrote

Wrote



Great it works now. I just have to figure it out how to implement it for the rest of the file .
Thank you very much!

How would you tackle this one?



Divide n by 2, a bit of rounding and offset adjustment should do the job.



I can't seem to get it to work, and for next examples i need to match it with a list that has some randomnes in number list. Isn't there a way i can create a list of number and if my "n" matches that list then i can get the correct value? I tried with for, if and so on. but im still a newbie in Smath.

Thank you once again!



If there is no rule, then you have to provide a vector with values and adress it with index n. A simple lookup table by index. Fill the vector by hand, by reading a file or asking a chatbot.
Martin Kraska Pre-configured portable distribution of SMath Studio: https://en.smath.info/wiki/SMath%20with%20Plugins.ashx
#10 Posted: 3/19/2024 2:49:03 PM
Alex Costila

Alex Costila

1 likes in 13 posts.

Group: User

Wrote

If you have a limited set of choiches, this might be a solution.

Screenshot 2024-03-18 141755.png

Also, I think Martin has a point, since these "n" values should come from some formula.



This works but i have other areas with diferent increment and i can't control them with interval. I will list a few of them:

here is 1,2,3 then goes to 16,17,18 then 26,27,28.

So i have this interval from the picture above and the one before with "Latimea benzii".
#11 Posted: 3/19/2024 3:57:49 PM
Alex Costila

Alex Costila

1 likes in 13 posts.

Group: User

Wrote

Wrote

If you have a limited set of choiches, this might be a solution.

Screenshot 2024-03-18 141755.png

Also, I think Martin has a point, since these "n" values should come from some formula.



This works but i have other areas with diferent increment and i can't control them with interval. I will list a few of them:

here is 1,2,3 then goes to 16,17,18 then 26,27,28.

So i have this interval from the picture above and the one before with "Latimea benzii".



Found a not very fancy solution, but it works .
pick a number from a list.sm (6 KiB) downloaded 23 time(s).
  • New Posts New Posts
  • No New Posts No New Posts