Vector column

Hi, I have a vector that has 100 rows and two columns. I want to select the second column. Julia gives an error with the following command. Can anyone help me?
box=[0,1,0,1]
ninit= 100
pdp = [LinRange(box[1],box[2],ninit),box[3].+1e-4.*rand(ninit,1)]
pdp_end = ninit
tmp = pdp[1:pdp_end,2]

you don’t:


julia> pdp = [LinRange(box[1],box[2],ninit),box[3].+1e-4.*rand(ninit,1)]
2-element Vector{AbstractArray{Float64}}:
 range(0.0, stop=1.0, length=100)
 [6.5964924515518e-5; 4.554730444196513e-5; … ; 7.90834654968606e-5; 6.505428036713388e-5;;]

you have a vector of two elements, each element is <: AbstractArray, one of them is a Range, the other one is a 100x1 Matrix.


you probably wanted:

julia> [LinRange(box[1],box[2],ninit);; box[3].+1e-4.*rand(ninit,1)]
100×2 Matrix{Float64}:
 0.0        2.98283e-5
 0.010101   1.1944e-5
 0.020202   2.74975e-5
...
..
.

Thank you for your answer. This command gives me a vector with 200 rows and a column. I want a matrix with 100 rows and 2 columns.

Previous solution works in Julia 1.7 or later. You can simply replace the comma , separating the two vectors in your original pdp assignment, by space.

Thanks for your answer. My problem was solved

2 posts were split to a new topic: Undefined variable in loop