Minimum Time Optimal Control

How can I reformulate my problem to generate a “bang-bang” control solution using CVX in Matlab?

I have a discrete LTI system:

X(N+1) = AX(N) + BU

and I need to find the minimum time horizon “N” subject to:

Umin <= U <= Umax
X(1) = X0
X(N+1) = Xdes.

Currently I have:
cvx_begin quiet
variable X(nrows,N+1);
variable u(1,N);
minimize(norm(u,inf));
subject to
X(:,2:N+1) == AdX(:,1:N)+Bdu;
X(:,1) == X0;
X(1,N+1) == Xdes;
cvx_end

This gives me closely what I’m looking for as long as I know N ahead of time.

Could I get a simple example on how to setup this problem?