你能帮帮我吗?我想在 Julia 中生成一个结构体。在 matalab 中,我们可以使用 repmat 作为结构体。但在朱莉娅这是不可能的。Julia中有没有像repmat这样的功能?
例如:
npop=20;
struct individual
position
cost
end
individual1=individual([],[])
repmat(individual1,npop,1)
repeat(individual1,npop,1)
repmat(individual1,npop,1)
ERROR: MethodError: no method matching repmat(::individual, ::Int64, ::Int64)
Closest candidates are:
repmat(::Union{AbstractArray{T,1}, AbstractArray{T,2}} where T, ::Int64, ::Int64) at abstractarray
math.jl:311
repmat(::Union{AbstractArray{T,1}, AbstractArray{T,2}} where T, ::Integer, ::Integer) at abstracta
rraymath.jl:334
repmat(::AbstractArray{T,1} where T, ::Int64) at abstractarraymath.jl:325
...
Stacktrace:
[1] macro expansion at C:\Users\admin\AppData\Local\JuliaPro-0.6.4.1\pkgs-0.6.4.1\v0.6\Atom\src\rep
l.jl:118 [inlined]
[2] anonymous at .\<missing>:?
julia>
julia> repmat(individual1,npop,1)
ERROR: MethodError: no method matching repmat(::individual, ::Int64, ::Int64)
Closest candidates are:
repmat(::Union{AbstractArray{T,1}, AbstractArray{T,2}} where T, ::Int64, ::Int64) at abstractarray
math.jl:311
repmat(::Union{AbstractArray{T,1}, AbstractArray{T,2}} where T, ::Integer, ::Integer) at abstracta
rraymath.jl:334
repmat(::AbstractArray{T,1} where T, ::Int64) at abstractarraymath.jl:325
...
Stacktrace:
[1] macro expansion at C:\Users\admin\AppData\Local\JuliaPro-0.6.4.1\pkgs-0.6.4.1\v0.6\Atom\src\rep
l.jl:118 [inlined]
[2] anonymous at .\<missing>:?
如果使用循环,则有可能
pop=individual([],[])
for i=2:npop
pop=[pop;individual1]
end
和
julia> pop
20-element Array{individual,1}:
individual(Any[], Any[])
individual(Any[], Any[])
individual(Any[], Any[])
individual(Any[], Any[])
individual(Any[], Any[])
individual(Any[], Any[])
individual(Any[], Any[])
individual(Any[], Any[])
individual(Any[], Any[])
individual(Any[], Any[])
individual(Any[], Any[])
individual(Any[], Any[])
individual(Any[], Any[])
individual(Any[], Any[])
individual(Any[], Any[])
individual(Any[], Any[])
individual(Any[], Any[])
individual(Any[], Any[])
individual(Any[], Any[])
individual(Any[], Any[])
但我在 Julia 中找不到像 repmat 这样的函数。