As the title suggest I was curious if Julia base or LinearAlgebra had some existing equivalent to Matlab’s implementation of assigning values to a non-exisiting index:
>> Array = [];
Array(3) = 3; Array(5) = 5; Array(3,6:7) = [6, 7];
Array
>> Array =
0 0 3 0 5 0 0
0 0 0 0 0 0 0
0 0 0 0 0 6 7
As you can see, it fills or preallocates the previous values with zeros. I was hoping that there would be already some optimized and general implementation of this out there for Julia. I already tried making my own function (see below), but ran into problems with append! only seeming to accept vectors. I believe I still need a lot of checks in order to generalize it, since I would want it to be able to do something like “Array(3,6:7) = [6, 7]” in the example above.
function writeI!(Array,Index,Values)
for i = 1:length(Index)
j = Index[i]
if j <= length(Array)
Array[j] = Values[i]
else
append!(Array,zeros(j-1-length(Array)),Values[i])
end
end
end
Edit: I said base or LinearAlgebra, but if there are already other packages that do this I would like to know as well