If I have a conditional of the form:
Which[Round[b[i], 0.1] == 74,1,40 < b[i] < x,2]
where b[i]
represents a number that gets updated in a loop and x is the variable I am asking for below.
How can I save the value of Round[b[i], 0.1] == 74
as a variable (let's say x
as in the code) only for when the condition Round[b[i], 0.1] == 74
is met. So, to be more specific if b[i]=73.99
, for example, then the code would translate to Which[Round[73.99, 0.1] (*which is equal to 74*) == 74,1,40 < b[i] < 73.99,2]
but if b[i]=75
, for example, then it will keep being Which[Round[75, 0.1] == 74,1,40 < b[i] < x,2]
as Round[b[i]]
is still not 74 and hence x
is still a variable with nothing assigned to. Is this possible?
Edit: I will also appreciate comments on getting Round[b[i], 0.1] == 74
equal to a variable even when the condition is not met, which should be simpler to do. For this case I tried naively Which[x==Round[b[i], 0.1] == 74,1,40 < b[i] < x,2]
but here x will be "True" or "False" but not the number.
I hope this makes sense and I appreciate in advanced your help
Thank you!
x = Round[73.99, 0.1]; If[x == 74, .etc....]
? $\endgroup$Which
to evaluate to when thex
variable is unassigned? This feels like an XY problem.. $\endgroup$