MATLAB: Generating Random (x y z) Coordinates Constrained by Euclidean Distance

constrained random variablesuniform distribution

I would like to write a function to generate randomized xyz coordinates from a set starting coordinates where the Euclidean distance from each original coordinate to its respective new, randomized coordinate would be no greater than 1.5 mm. I would like this process to repeat as many times as I specify (m = # of repetitions). More specifically, the function would take as input an nx3 matrix of xyz coordinates (each row is a separate observation, columns 1, 2, and 3 are x-, y-, and z-coordinates respectively), and outputs an m x 1 cell, where each element of the cell contains an nx3 matrix of the randomized xyz coordinates.
I can think of an ugly way to do this with a while loop and if/else statements, but I was wondering if there was a clean way to do this within the statistics toolbox. I want to use a uniform distribution to generate these numbers.
Thanks! LH

Best Answer

I don't think you will find this in the stats toolbox.
The process is equivalent to finding points within a sphere of given radius.
If I recall correctly, in the File Exchange, Roger Stafford has a contribution for finding points on a sphere; perhaps that could be adapted.