There's nothing predefined that does this, but it's easy to roll your own:
preallocate and output array of the correct size (a pretty straightforward
computation) and then use a for loop to copy the elements over; wrap this
in a function and then use as desired.

On Tue, Jun 14, 2016 at 11:37 AM, Jesse Jaanila <[email protected]>
wrote:

> I would like to know whats a juliatic way of indexing or slicing evenly
> spaced ranges out of an array:
>
> If I want to take out every n:th element out of Julia array, I would do
> something like
>
> a = [1,2,3,4,5,6];
> everySecond = a[2:2:end];
>
> What I would like to achieve is a slice of specified size between evenly
> spaced step sizes. So after n length step, collect a slice of specified
> length.
> So if I have step size as 1 and then I want to take the next two elements
> I would expect the result to be:
>
> a = [1,2,3,4,5,6,7,8,9,10];
>
> magicIndexing(a)
> >[2,3,5,6,8,9]
>
> Is there a nice way of achieving something like this?
>

Reply via email to