-
I'm trying to collect several columns of mathjs statements and execute them each against an incrementing counter For example:
There is an additional complication to my problem: each column is 1 second, and we desire to create the waveform of an audio file. That means, between each column, interpolate the values of It's easy enough to create a range for x, To do this efficiently, my first idea was to declare the entire column as an
For example, this fails:
I understand this is the classic "XY problem" (ha!), but I will certainly accept an answer that solves my X problem instead. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
I think there are specific plans to implement functions with multiple statements according to #2701 In the meantime a workaround is that elements of an array can include expressions with assignments. f(x) = [d = 1, d][end] # evaluate all expressions in the array and return only the value of the last expression.
f(3) # 1 You have to be very careful with your naming convention as the expressions will assign values in the scope (there are not function scopes) d = 5
f(x) = [d = 1, d][end] # evaluate all expressions in the array and return only the value of the last expression.
d # 5
f(3) # yields 1 but overrides the value of d
d # 1 Now for your original problem, I don't think that functions with multiple steps are mandatory for your problem. Maybe it's more of an issue with vectorization, can you use an additional dimension to solve your issue in one go? |
Beta Was this translation helpful? Give feedback.
I think there are specific plans to implement functions with multiple statements according to #2701
In the meantime a workaround is that elements of an array can include expressions with assignments.
You have to be very careful with your naming convention as the expressions will assign values in the scope (there are not function scopes)