I have an error where if I call a function once it runs without issue, but if I call it a second time on a different argument, it doesn’t run and instead returns an inexact error. This leads me to believe that the function itself might be over-writing the input variable/
Here is how I am calling the function
dvhhhh=C2D(dvh2)
dvhhhh2=C2D(dvh2)
The first line runs without issue, the second line returns an Inexact error.
Below is the code of the function C2D, as far as I can tell this function does not change the input array, dvht, but this must be what is happening as I’m calling the same function on the same argument but it only works the first time.
function C2D(dvht) #Utility Function to convert dvh from cumulative todifferentia
dvh=dvht #store in dummy variable so as not to overwrite the dvh
nb = length(dvh[:, 2])
for i = 2:nb
#Start with column 1 (corresponding to dose bins we will need
#to make). Set the dose value to be the midpoint between the dose
#and the one after it, this is the Dose value corresponding to
#this bin.
dvh[i-1, 1] = dvh[i-1, 1] + (dvh[i, 1] + dvh[i-1, 1]) / 2
#
dvh[i-1, 2] = dvh[i-1, 2] - dvh[i, 2] # % volume in this bin will just
#be the difference in % this and the previous row's relative volume %
end
dvh[:, 1] = 0.01 * dvh[:, 1]#optional, This assumes the dose in is in cGy, we convert to Gy
dvh = dvh[1:end.!=nb, :]
dvh #return the differential dvh
end
If it helps, dvh2 is iniitally set to [0 100; 12000 0];
, but has its value changed to a 2×2 Array{Int64,2}: [60 100; 120 0]
After I run the C2D function on it. Yet I cannot see how the C2D function over-writes the input variable or why. I am assuming that the variable names in a function behave the same way as in MATLAB (i.e. they are entirely encoded within the function, not outside of it).