When working on matrices / arrays I was gladly surprised with the capability to index with end.
By doing some tests, I found it a bit odd that a few examples didn't work as expected and some more complex ones did work very well.
A = 11:20 # [11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
A[end] # 20
A[:end] # [11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
A[end-1] # Error: Undefined symbol end
A[:end-1] # [11, 12, 13, 14, 15, 16, 17, 18, 19]
A[end/2] # Error: Undefined symbol end
A[:end/2] # [11, 12, 13, 14, 15]
A[end/2:end-1] # [15, 16, 17, 18, 19]
A[end/2:2:end-1] # [15, 17, 19]
A[round(end/2)] # Error: Undefined symbol end
A[round(end/2):2:end-1] # [15, 17, 19]
I was expecting for these to work like so:
A[end-1] # 19
A[end/2] # 15
A[round(end/2)] # 15
So I think end isn't recognized when it's not on a range and it isn't by itself (not being affected by operations or functions).
As a workaround I defined my own END and it seems to work.
END = size(A)[1] # 10
A[END-1] # 19
A[END/2] # 15
A[round(END/2)] # 15
When working on matrices / arrays I was gladly surprised with the capability to index with
end.By doing some tests, I found it a bit odd that a few examples didn't work as expected and some more complex ones did work very well.
I was expecting for these to work like so:
So I think
endisn't recognized when it's not on a range and it isn't by itself (not being affected by operations or functions).As a workaround I defined my own
ENDand it seems to work.