I'd like to program a conditional statement that checks if an optional events function for an ODE was triggered. This would look something like:
if ~isfield(sol,'xe') || isempty(sol.xe) fprintf('Event Not Triggered\n')else fprintf('Event Triggered\n')end
However, this fails if sol.xe doesn't exist because no events function was specified. In the interest of shorter/cleaner code, I'd like to avoid this solution:
if isfield(sol,'xe') if isempty(sol.xe) fprintf('Event Not Triggered\n') else fprintf('Event Triggered\n') endelse fprintf('Event Not Triggered\n')end
Is there a better way to do this?
Best Answer