Is there a way to make a variable inside a function a "semi" global variable? Not sure that I am using the right wording, but for example, inside a function I have
try
pixel_size = header[(0x0028, 0x0030)]
catch
FOV = header[(0x0018, 0x1100)]
matrix_size = header[(0x0028, 0x0010)]
pixel_size = FOV / matrix_size
end
and I want to make pixel_size
available to the rest of the function but not necessarily globally. Is there a way to do this?
You should be able to just do
local pixel_size
try
pixel_size = header[(0x0028, 0x0030)]
catch
FOV = header[(0x0018, 0x1100)]
matrix_size = header[(0x0028, 0x0010)]
pixel_size = FOV / matrix_size
end
Ooh, simple enough. Thanks!
Dale Black has marked this topic as resolved.
I should also mention that my preferred method would be to simply write
pixel_size = try
header[(0x0028, 0x0030)]
catch
FOV = header[(0x0018, 0x1100)]
matrix_size = header[(0x0028, 0x0010)]
FOV / matrix_size
end
Because everything is an expression in Julia
Oh wow, that's very cool
I like that better too
Last updated: Nov 06 2024 at 04:40 UTC