The task appears simple, but i am struggling to get the way of initializing a vector (array, collection, or similar) of ranges. That is, I need to do something like this:
vec_of_ranges = HOW TO INITIALIZE THIS?
for i=1:10
range = i:20
vec_of_ranges[i]=range
end
Can anyone give me a hint on how to do this? I need it so I can then evaluate a given array on that collection of ranges...
Thanks in advance!
For example if start = 1,stop = 100 and length = 10, then we will have range as 1.0:11.0:100.0 Where 11.0 is difference between two subsequent objects in the range. For this example, we will have a range of objects as 1.0, 12.0, 23.0, ... 100.0 .
A 1D array can be created by simply writing array elements within square brackets separated by commas(, ) or semicolon(;). A 2D array can be created by writing a set of elements without commas and then separating that set with another set of values by a semicolon.
A Vector in Julia can be created with the use of a pre-defined keyword Vector() or by simply writing Vector elements within square brackets([]). There are different ways of creating Vector. vector_name = [value1, value2, value3,..] or vector_name = Vector{Datatype}([value1, value2, value3,..])
If you type typeof(1:50)
you get UnitRange{Int64}
So you need an array of UnitRange
Try this:
vec_of_ranges = Array{UnitRange{Int64},1}(undef, 10)
for i=1:10
range = i:20
vec_of_ranges[i]=range
end
You might also want to use the fill()
command
vec_of_ranges = fill(1:20, 10)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With