In matlab, we could use X = to define an empty array and then add elements in X like X[1] = 2 or X[i] = rand in a for loop and does not require us to know the size of X in advance.
I was wondering how could I do this in Julia? Here is my code,Coo is a 500-element Vector{Vector{Float64}}.
using Plots
using JLD
using StaticArrays
Coo = load("data.jld")["data"]
x = load("data2.jld")["data"]
y = load("data3.jld")["data"]
gx = []
for i = 1:length(Coo)
if Coo[i][1] >4 & Coo[i][2] <4
gx[i] = Coo[i][1]
end
end
This line
Coo[i][1] >4 & Coo[i][2] <4
and this line here
gx[i] = Coo[i][1]
both failed and have problems. Sorry that I feel confused to debug them at this stage.
Could you please give some suggestions or comment on this?
Thank you in advance!
help?> &
search: & &&
x & y
Bitwise and. Implements three-valued logic [...]
help?> &&
search: &&
x && y
Short-circuiting boolean AND.
See also &, the ternary operator ? :, and the manual section on control flow.
If you enter ? in the REPL and enter a symbol, function name, operator etc., you’ll get this sort of documentation. Most packages and almost everything in julia Base has this sort of documentation available.
In general, I’d recommend checking out the manual (especially the section about differences from Matlab) if you’re new to the language.