Matlab: How to set variable if it doesnt exist yet

The following code snippet shows how to set a variable in Matlab only if it doesn’t exist yet:

if ~exist('my_variable', 'var')
    my_variable = 0; % or whatever default value you want to set
end