function myfunc()
A=[test(1:10),test(2:11)]
B=Array{test}(undef,2)
for i =1:2
temp=test([]) # <----
flag=findall(x-> x<5,A[i].a)
temp.a=A[i].a[flag]
B[i]=temp
end
B
end
julia> function myfunc()
A=[test(1:10),test(2:11)]
B=Array{test}(undef,2)
for i =1:2
temp=test([])
flag=findall(x-> x<5,A[i].a)
temp.a=A[i].a[flag]
B[i]=temp
end
B
end
myfunc (generic function with 1 method)
julia> myfunc()
2-element Array{test,1}:
test([1, 2, 3, 4])
test([2, 3, 4])
function myfunc()
A=[test(1:10),test(2:11)]
B=Array{test}(undef,2)
temp=test([])
for i =1:2
flag=findall(x-> x<5,A[i].a)
temp.a=A[i].a[flag]
B[i]=temp
@show temp B
end
B
end
julia> myfunc()
temp = test([1, 2, 3, 4])
B = test[test([1, 2, 3, 4]), #undef]
temp = test([2, 3, 4])
B = test[test([2, 3, 4]), test([2, 3, 4])]
2-element Array{test,1}:
test([2, 3, 4])
test([2, 3, 4])
看上去是传引用的问题,或者可以 deepcopy()
一下
function myfunc()
A=[test(1:10),test(2:11)]
B=Array{test}(undef,2)
temp=test([])
for i =1:2
flag=findall(x-> x<5,A[i].a)
temp.a=A[i].a[flag]
B[i]=deepcopy(temp) # <----
end
B
end