Matlab: Wie man eine Variable setzt, wenn sie noch nicht existiert

Der folgende Code-Schnipsel zeigt, wie man eine Variable in Matlab nur setzt, wenn sie noch nicht existiert:

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

Check out similar posts by category: Matlab/Simulink