Notice the colon operators. Your ai is going to be a vector. Likewise your aj is going to be a vector.
You are trying to use integral2() passing in a vector of maximum x values in the variable ai, and a vector of maximum y values in the variable aj . integral2() must have scalar numeric upper and lower bounds for x (the 0,ai parameters you pass.) For the y bounds, the 0,aj that you pass, the values can be either numeric scalars or else a function handle to a function of a single variable that passes in the current x value and permits calculating the y bound in terms of x.
Note by the way that if the call worked, then you would be overwriting all of M each iteration, so M would end up being a scalar afterwards.