Change the element of the vector with respect to the element of the direction vector
If the element of the direction vector is 2, then the new element of the vector is two times the corresponding element in the vector.
If the element of the direction vector is 1, then the new element of the vector is two times the corresponding element in the vector minus one.
Attention: 'if' can not be used
Example
direction vector d = [1 2 2 2 1 2 1 2] vector = [1 2 3 4 5 6 7 8] new_vector = [1 4 6 8 9 12 13 16]
Interesting. [d==1] has a Cody size one greater than (d==1). Any thoughts as to why?
The brackets are the operation "conatenate elements" so it is interpreted as an extra operation. The expression [1:10] has the same meaning (result) as (1:10) but in the first case you have done an extra operation (not necessary in this case). On the same way you can use [1 5] but if you use (1 5) you become an error because there is no concatenation with simple parenthesis.
Nice. Thanks for the explanation, J.R.
5171 Solvers
Is this triangle right-angled?
1378 Solvers
Find the dimensions of a matrix
269 Solvers
Find the Nth Root of a Given Number
126 Solvers
197 Solvers