I would like to create a set of random points with a distance separating them from each other. I would also like to create various sets of random numbers

1 view (last 30 days)
Akshay Kumar Pakala
Akshay Kumar Pakala on 2 Nov 2021
For example i would like to create 50 random points that seprated by a distance of 20 from each other and another set of 27 random points that are seperated by a distance of 12 from each other. SImilarly, i would like to create a set of random for every bin of the histogram with the seperating distances respectively.
I am attaching the code that i used to generate the histogram
clear all
BW = imread('binary.PNG');
[nr,nc,layers] = size(BW);
%% converting the image to 2d so the image can be labledd %%
if layers>1
BW = BW(:,:,1);
% end of lablling %%%%%%%%%%%%%%%%%
binaryimage = BW < 128;
bw = logical(binaryimage);
imwrite(bw, 'imagetoapp.jpg');
%% lablelling the image %%%%%%
[labeledimage, numberofblobs] = bwlabel(binaryimage,8);
props = regionprops(labeledimage, 'Equivdiameter');
x = numel(props);
y = zeros(x,1);
for i = 1:1:length(props)
y(i,1) = struct2array(props(i,1));
%% LAbled image to rgb
colouredimage = label2rgb(labeledimage,'jet', [0,0,0.5]);
coloredLabelsImage = label2rgb (labeledimage, 'jet', 'k', 'shuffle');
hold on
%% generating histogram and curve fitting it using gaussian function%%%%%%%%%
y1 = histogram(y,45);
values = y1.Values;
for i = 1 : length(a)-1
b(i) = mean(a(i:i+1));
[barheights, position] = hist(y,45);
positiontranspose = position';
valuestranspose = values';
gauss = 'd + a*exp(-(1/2)*((x-b)/c)^2)'
startpoints = [40 20 10 0.5];
myfit = fit(positiontranspose,valuestranspose,gauss,'start',startpoints);
hold on
z(:,1) = myfit(x);
%% plot properties
xlabel('seperation distances')
hold on; plot(b, zt, 'r*')
binary image
Akshay Kumar Pakala
Akshay Kumar Pakala on 10 Nov 2021
Hey chris,
thanks for the repy.
I understand your concern.
for eq lets take bin 4 [8.81 11.08]. The avg diameter at bin 4 is 9.945. radius = 4.9725. Thus, i would like to create 16 points (frequency displayed in y axis of the histogram) which are randombly distributed in 3d space but are 4.9725 away from each other and other points aswell.

Sign in to comment.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by