function [d,i] = increment(d,r,i) if d( i ) < r( i ) - 1 d( i ) = d( i ) + 1; i=i; else d( i ) = 0; [d,i] = increment( d,r,i + 1 ); end