function c = randcantor(p,n,d,varargin) %RANDCANTOR 1D, 2D or 3D generalized random Cantor set % C = RANDCANTOR(P, N, D) generates a logical D-dimensional array (with % D=1, 2, or 3) of size N^D, containing a set of fractally-distributed 1. % The size N must be a power of 2. C is obtained by iteratively dividing % an initial set filled with 1 into 2^D subsets, multiplying each by 0 % with probability P (with 0