It is hard to answer without an example, but it looks like you just want to perform a montecarlo simulation ?
Suppose your shape is defined by the function f and that you have limits X, Y stored in two element vectors, for example. xlim = [-10 10], that is, all possible x values โโof this form lie between x = -10 and x = 10, then I would suggest that you do f return some error code if there is no value for a particular xy pair. I guess it will be NaN . So f(x,y) is the function you write, either returns z if it can, or NaN if it cannot
n= 10000; counter = 1; shape = nan(n, 3) while counter < n x = rand*diff(xlim) + mean(xlmin); y = rand*diff(ylim) + mean(ylim); z = f(x,y) if ~isnan(z) shape(counter, :) = [x, y, z]; counter = counter + 1 end end
Thus, the above code will generate 10,000 (not unique, but easily adapted) points of random sampling according to your form.
Now, having typed this, I understand that maybe your figure is actually not that big, and maybe you can evenly try it out, and not randomly:
for x = xlim(1):xstep:xlim(2) for y = ylim(1):ystep:ylim(2) shape(counter, :) = [x, y, f(x,y)]; end end
or if you write f for vectorization (preferred)
shape = [(xlim(1):xstep:xlim(2))', (ylim(1):ystep:ylim(2))', f(xlim(1):xstep:xlim(2), ylim(1):ystep:ylim(2));
and then anyway
shape(isnan(shape(:, 3), :) = []; %remove the points that fell outside the shape