Hi all!
I’m running a simulation where I’m tracking the behavior of multiple elements over time. Say like the instantaneous speed of several cars on a race track. I can use the command
sim_time, spd_c1 = get_state_series(results, ("Car 1", :speed))
to get the time steps (saved as sim_time which is type Vector{Float64}) and the speed of Car 1 (saved as spd_c1 which is type Vector{Float64}) which I can then plot with PlotlyJS using the command
plot([scatter(x=sim_time, y=spd_c1, mode="lines", name="Car 1")])
which is fine, except I have to manually specify the name of each car I want to gather results from manually. I’d like to be able to gather all the results for all the cars for plotting automatically, but I’m struggling with how to accomplish this.
I’ve tried something like:
c1 = [2, 6, 8, 2]
c2 = [3, 20, 12, 1]
c3 = [6, 12, 4, 8]
sim_time = [1, 2, 3, 4]
for n in [c1, c2, c3]
global car_spd = similar(sim_time)
push!(car_spd, n)
return car_spd
end
display(car_spd)
But I get the error
ERROR: MethodError: Cannot `convert` an object of type Vector{Int64} to an object of type Int64
Closest candidates are:
convert(::Type{T}, ::ColorTypes.Gray24) where T<:Real at ~/.julia/packages/ColorTypes/1dGw6/src/conversions.jl:114
convert(::Type{T}, ::ColorTypes.Gray) where T<:Real at ~/.julia/packages/ColorTypes/1dGw6/src/conversions.jl:113
convert(::Type{T}, ::Ptr) where T<:Integer at pointer.jl:23
...
Stacktrace:
[1] push!(a::Vector{Int64}, item::Vector{Int64})
@ Base ./array.jl:1057
[2] top-level scope
@ ./Untitled-1:8
Whereas I was hoping for a result that looked something like
[2, 6, 8, 2;
3, 20, 12, 1;
6, 12, 4, 8]
Any ideas?