Assign certain values to a variable

Assign certain values to a variable - 消息

#1 已发布: 2021/9/1 10:44:15
Stefan Müller

Stefan Müller

0个赞,共45个帖子。

组: User

Hallo guys i have a problem and i dont know how to write it in smath.

for example:

i have a variable and i want to assign certain values depending on other values.

for example:

Variables:

a=1
b=2
e=1 or 2 for example

and now:

c:= a if e=1
b if e=2


and then

OK if c=1
NOK if c=2

also i can remember the function sverweis in mathcad to assign certain values to a variable out of a matrix

i dont know how to write in smath
i know its easy example but its only for demonstration

I know how to write in mathcad but not in smath
thank you br Stefan
#2 已发布: 2021/9/1 11:28:36
Jean Giraud

Jean Giraud

983个赞,共6,866个帖子。

组: User

Attach your Smath work sheet !
#3 已发布: 2021/9/1 11:41:06
Stefan Müller

Stefan Müller

0个赞,共45个帖子。

组: User

Test.sm (5.83 KiB)已下载 1214 次。

just trying. I think i got it but is there a better way to assign such values?

I just want to do it with if only

So that

e:= if a=1 then e=10
if a=2 then e=11
if a=3 then e=12
if a=4 then e=13
if a=5 then e=14
if a=6 then e=15

like this way



and so on not with if else if else is a little bit confusing


thank you best regards stefan
#4 已发布: 2021/9/1 11:56:16
Stefan Müller

Stefan Müller

0个赞,共45个帖子。

组: User

i think i have a similar problem like this on here:


https://en.smath.com/forum/yaf_postst723_if-without-else.aspx


if without else

is there somehow a workaround?
#5 已发布: 2021/9/1 13:04:53
Fridel Selitsky

Fridel Selitsky

520个赞,共451个帖子。

组: User

One of the options
1位用户喜欢此帖子
Stefan Müller 2021/9/1 15:09:00
#6 已发布: 2021/9/1 13:25:26
Stefan Müller

Stefan Müller

0个赞,共45个帖子。

组: User

thank you but im having troubles writing this code.

How you write the if without else and how do you write the otherwise


i see no otherwise and i always have the if with else statement

or do i need a plugin for your function?

thank you
#7 已发布: 2021/9/1 13:56:54
Fridel Selitsky

Fridel Selitsky

520个赞,共451个帖子。

组: User

Wrote a little differently
Test Mod.sm (6.62 KiB)已下载 1246 次。
1位用户喜欢此帖子
Stefan Müller 2021/9/1 15:09:00
#8 已发布: 2021/9/1 14:02:57
Stefan Müller

Stefan Müller

0个赞,共45个帖子。

组: User

ok thank you i think i got a solution for now

Worksheet1.sm (7.91 KiB)已下载 1249 次。

thank you
#9 已发布: 2021/9/1 14:21:59
Stefan Müller

Stefan Müller

0个赞,共45个帖子。

组: User

Decision Variable.sm (7.85 KiB)已下载 1276 次。

i now encounter another problem. If i have many decisions how can i align the variables vertically?

I have not enough place on the sheet so that every variable can stay there in one row

like in the sheet
#10 已发布: 2021/9/1 16:18:07
Jean Giraud

Jean Giraud

983个赞,共6,866个帖子。

组: User

Wrote

not with if else


Try if/otherwise from f(x) menu cases

if_otherwise.PNG
1位用户喜欢此帖子
Stefan Müller 2021/9/7 07:21:00
#11 已发布: 2021/9/1 16:39:03
overlord

overlord

600个赞,共1,381个帖子。

组: Moderator

Are you trying to achieve this?
It takes very little space on sheet.
You did mentioned vlookup function.
This gives a variable depending on a decision.
Or maybe I have lost in the context.

Regards

decision_r1.sm (4.12 KiB)已下载 1189 次。

2021-09-01_22-38.png
1位用户喜欢此帖子
Stefan Müller 2021/9/7 07:21:00
#12 已发布: 2021/9/2 03:17:31
Stefan Müller

Stefan Müller

0个赞,共45个帖子。

组: User

@ Jean i dont find this f(x) menü cases. Do i need a plugin for this feature?

can you describe me how i do get to this if otherwise statement?


Thank you for the support so far. Im really beginner to smath
#13 已发布: 2021/9/2 03:26:01
Davide Carpi

Davide Carpi

1,443个赞,共2,936个帖子。

组: Moderator

Wrote

@ Jean i dont find this f(x) menü cases. Do i need a plugin for this feature?

can you describe me how i do get to this if otherwise statement?


Thank you for the support so far. Im really beginner to smath



It is the function cases from custom functions plugin. To add more "if cases" you have to type twice your argument separator key.

If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
1位用户喜欢此帖子
Stefan Müller 2021/9/7 07:21:00
#14 已发布: 2021/9/2 08:05:15
Jean Giraud

Jean Giraud

983个赞,共6,866个帖子。

组: User

Wrote

@ Jean i don't find this f(x) menü cases. Do I need a plugin for this feature?
Can you describe me how I do get to this if otherwise statement ?



Cases [if_otherwise].PNG

1位用户喜欢此帖子
Stefan Müller 2021/9/7 07:21:00
#15 已发布: 2021/9/2 08:30:15
overlord

overlord

600个赞,共1,381个帖子。

组: Moderator

Wrote

Do i need a plugin for this feature?
Can you describe me how i do get to this if otherwise statement?
Thank you for the support so far. I'm really beginner to smath


You need to install Custom Functions plugin.
After you have installed Custom Functions plugin;
You can either enter it from menu, Insert > Function > Cases().
Or you can press Ctrl+E key combination and insert Cases().
Or simply type cases(), press Tab or click on it and will be added.
Last one is how most people insert it I guess.

Please don't hesitate to ask anything.
You will find out this is one of the most friendly forums on internet.
Everyone is eager to help and shall try to reply your questions.

Regards
1位用户喜欢此帖子
Stefan Müller 2021/9/7 07:22:00
#16 已发布: 2021/9/2 08:43:08
Stefan Müller

Stefan Müller

0个赞,共45个帖子。

组: User

Ok thank you i think i got it i can expand it with a "shift" + "," pushing then if cases will be added
  • 有新帖
  • 无新帖