Vectors
Vectors in AUXLAB behave much like vectors in MATLAB-style numerical environments, but the language also keeps the syntax consistent with audio-oriented operations.
Indexing
- The colon operator
:can be used to represent consecutive indices.
AUX> x(20:25)
x(20:25) = 81 80 79 78 77 76
- Any vector can also be used as an index into a vector.
AUX> x([2 5 10:13])
x([2 5 10:13]) = 99 96 91 90 89 88
- The reserved word
end, if used inside indexing parentheses, denotes the last index in the array.
AUX> x(end-1:end) // here end means 100, because the length of x is 100
x(end-1:end) = 2 1
Vector Arithmetic
- A vector plus a scalar means the scalar is added to all elements.
AUX> 10 + [1 2 3]
ans = 11 12 13
- A vector plus another vector produces a vector of element-wise addition where both operands are available. The output follows the longer operand.
AUX> [1 2 3] + [1 2 3 4 5]
ans = 2 4 6 4 5
Assignment And Replacement
- Existing elements can be modified by assignment.
AUX> x(9)=0
x = 100 99 98 97 96 95 94 93 0 91 ... (length = 100)
AUX> x(1:3)=[29 8 -1]
x = 29 8 -1 97 96 95 94 93 0 91 ... (length = 100)
- For consecutive indexing, the number of elements on the left and right side do not need to match. This means “replace the selected region with the new values.”
AUX> x(1:4)=[55 56]
x = 55 56 96 95 94 93 0 91 90 89 ... (length = 98)
- For non-contiguous indexing, both sides must match in element count.
AUX> x([1 3 4])=[55 56]
(ERROR MESSAGE!!!)
AUX> x([1 3 4])=[-1 -2 -3]
x = -1 -2 96 -3 94 93 0 91 90 89 ... (length = 98)
- As an exception, a scalar on the right-hand side can be repeated for multiple target indices.
AUX> x(1:3)=0
x = 0 0 0 -3 94 93 0 91 90 89 ... (length = 98)
AUX> x([1:3 8 10])=-1
x = -1 -1 -1 -3 94 93 0 -1 90 -1 ... (length = 98)
Compound Assignment
When a compound operator is used (+=, -=, *=, /=, or %=), the affected left-hand-side elements are updated according to the indexing selection.
AUX> x([1:3 8 10])+=1
x = 0 0 0 -3 94 93 0 0 90 0 ... (length = 98)
Conditional Indexing
- If a conditional statement is present inside the parentheses, indexing follows only where the condition is true.
AUX> x=(0:100).sqrt
x = 0 1 1.414 1.732 2 2.236 2.449 2.645 2.828 3 ... (length = 100)
AUX> x(x>3 && x<4)
ans = 3.162 3.317 3.464 3.606 3.742 3.873
- Assignments with conditional indexing can be handy.
AUX> x=1:100
x = 1 2 3 4 5 6 7 8 9 10 ... (length = 100)
AUX> x(x%2==0)=99
x = 1 99 3 99 5 99 7 99 9 99 ... (length = 100)
- Compound assignments with conditional indexing can be even more concise.
AUX> x=1:100
x = 1 2 3 4 5 6 7 8 9 10 ... (length = 100)
AUX> x(x%2==0)*=10
x = 1 20 3 40 5 60 7 80 9 100 ... (length = 100)
Current source basis:
vectors.html