Also (this is very late in the game to be adding to this, but this frustrates me). Here is a solution with nested functions:
function [ dealfunchandle ] = dealwithit( arrayfunc )
% Takes as input an event function of (t,z) that returns a 3 array (in same order as event syntax).
function [a, b, c] = dealfunc(t,z)
output = arrayfunc(t,z);
a = output(:,1);
b = output(:,2);
c = output(:,3);
end
dealfunchandle = @dealfunc;
end
This function only has to be written once (handy if you have to use lots of different event functions). This can be used to generate an anonymous event function within the code as follows:
arrayfunc = @(t,y) [y(1), 0, 1];
events = dealwithit(arrayfunc);
opts = odeset('Events', events);
And then ode45 as per normal.