I'm trying to do the following in MATLAB

call a loop - `for i=1:1000` and inside the loop I optimize a function using `fminunc`. Optimization is over a vector of parameters, one of which appears in a matrix in the function. Now it seems that `fminunc` calls an algorithm that inverts the matrix and then searches for a minimum. What happens is that when searching for a minimum a value that makes the matrix non-inverteble is given, and as MATLAB tries to invert the matrix, it spits an error and the loop stops. Is there a way I can adjust for this? Or perhaps less ideally, can I make it such that whenever this happens, MATLAB just ignores the optimization for that value of i and continues with `i+1`?